相关疑难解决方法(0)

处理ARC中的指针到指针所有权问题

假设对象A有一个属性:

@property (nonatomic, strong) Foo * bar;
Run Code Online (Sandbox Code Playgroud)

在实现中合成为:

@synthesize bar = _bar;
Run Code Online (Sandbox Code Playgroud)

对象B操纵a Foo **,如本示例中对象A的调用:

Foo * temp = self.bar;
[objB doSomething:&temp];
self.bar = temp;
Run Code Online (Sandbox Code Playgroud)
  • 这个或类似的东西可以合法地完成吗?
  • doSomething:方法的正确声明是什么?

此外,假设在我有机会设置属性之前可以释放对象Bbar(从而获取指向的实例的所有权temp) - 我如何告诉ARC切换拥有的引用?换句话说,如果我想让以下示例代码段起作用,我将如何处理ARC问题?

Foo * temp = self.bar;    // Give it a reference to some current value
[objB doSomething:&temp]; // Let it modify the reference
self.bar = nil;           // Basically release whatever we have
_bar = temp;              // Since we're …
Run Code Online (Sandbox Code Playgroud)

objective-c automatic-ref-counting

41
推荐指数
2
解决办法
1万
查看次数

自动引用计数问题:将非本地对象的地址传递给__autoreleasing参数以进行回写

我正在尝试将指针传递给指向某个方法的指针,但显然ARC在如何操作方面存在一些问题.这里有两种方法:

+ (NSString *)personPropertyNameForIndex:(kSHLPersonDetailsTableRowIndex)index 
{
    static NSArray *propertyNames = nil;

    (nil == propertyNames) ? 
        [self SHL_initPersonPropertyNamesWithArray:&propertyNames] : NULL;
}

+ (void)SHL_initPersonPropertyNamesWithArray:(NSArray **)theArray
{
    *theArray = [[NSArray alloc] 
                 initWithObjects:@"name", @"email", @"birthdate", @"phone", nil];
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

自动引用计数问题:将非本地对象的地址传递给__autoreleasing参数以进行回写

在出现以下命令的行上:

[self SHL_initPersonPropertyNamesWithArray:&propertyNames] : NULL;
Run Code Online (Sandbox Code Playgroud)

pointers objective-c ios5 automatic-ref-counting

14
推荐指数
1
解决办法
9856
查看次数

ARC转换的应用程序问题:将非本地对象的地址传递给_autoreleaseing参数以进行回写

我正在尝试用ios5制作应用程序,我真的很困惑,为什么会发生这种情况.有人可以帮我解释一下为什么出现错误时出现错误

将非本地对象的地址传递给__autoreleasing参数以进行回写

以下调用导致错误

// note the following method returns _inStream and _outStream with a retain count that the caller must eventually release

if (![netService getInputStream:&_inStream outputStream:&_outStream]) {

 NSLog(@"error in get input and output streams");
 return;
}
Run Code Online (Sandbox Code Playgroud)

我的班级.h

NSInputStream      *_inStream;
NSOutputStream     *_outStream;

@property (nonatomic, strong) NSInputStream *_inStream;    
@property (nonatomic, strong) NSOutputStream *_outStream;
Run Code Online (Sandbox Code Playgroud)

我的班级.m

@synthesize _inStream;
@synthesize _outStream;
Run Code Online (Sandbox Code Playgroud)

所述的getInputStreamNSNetService类方法

请在下面的NSNetService类getInputStream实现

/* Retrieves streams from the NSNetService instance. The instance's delegate methods are not called. Returns YES if the …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c automatic-ref-counting

2
推荐指数
1
解决办法
4176
查看次数