我需要在NSArray中存储对对象的弱引用,以防止保留循环。我不确定要使用的正确语法。这是正确的方法吗?Foo*foo1=[[Fooalloc]init];Foo*foo2=[[Fooalloc]init];__unsafe_unretainedFoo*weakFoo1=foo1;__unsafe_unretainedFoo*weakFoo2=foo2;NSArray*someArray=[NSArrayarrayWithObjects:weakFoo1,weakFoo2,nil];请注意,我需要支持iOS4.x,因此使用__unsafe_unretained而不是__weak。编辑(
只是想确保我做对了:我是否需要__unsafe_unretain我不拥有的对象?如果一个对象是__unsafe_unretained我需要在@property中使用assign吗?这是否意味着该对象没有被保留,而只是引用我分配给的对象?除了代表,我还想在什么时候使用它?这是ARC的东西还是以前使用过? 最佳答案 LLVMCompiler3.0引入了四个新的所有权限定符:__strong、__autoreleasing、__unsafe_unretained和__weak。根据thespecification,前三个甚至在ARC之外也
只是想确保我做对了:我是否需要__unsafe_unretain我不拥有的对象?如果一个对象是__unsafe_unretained我需要在@property中使用assign吗?这是否意味着该对象没有被保留,而只是引用我分配给的对象?除了代表,我还想在什么时候使用它?这是ARC的东西还是以前使用过? 最佳答案 LLVMCompiler3.0引入了四个新的所有权限定符:__strong、__autoreleasing、__unsafe_unretained和__weak。根据thespecification,前三个甚至在ARC之外也
ARC禁止在结构或联合中使用Objective-C对象,尽管标记了文件-fno-objc-arc?为什么会这样?我假设如果你标记它-fno-objc-arc你没有这个限制。 最佳答案 如果您收到此消息,请尝试__unsafe_unretained。只有在结构中的对象未被保留时,它才是安全的。示例:如果您将OpenFeint与ARC一起使用,则OFBragDelegateStrings类会在结构中显示此错误。typedefstructOFBragDelegateStrings{NSString*prepopulatedText;NSS
ARC禁止在结构或联合中使用Objective-C对象,尽管标记了文件-fno-objc-arc?为什么会这样?我假设如果你标记它-fno-objc-arc你没有这个限制。 最佳答案 如果您收到此消息,请尝试__unsafe_unretained。只有在结构中的对象未被保留时,它才是安全的。示例:如果您将OpenFeint与ARC一起使用,则OFBragDelegateStrings类会在结构中显示此错误。typedefstructOFBragDelegateStrings{NSString*prepopulatedText;NSS
使用ARC,我不能再将CGColorRef转换为id。我了解到我需要进行桥接类型转换。根据clangdocs:AbridgedcastisaC-stylecastannotatedwithoneofthreekeywords:(__bridgeT)opcaststheoperandtothedestinationtypeT.IfTisaretainableobjectpointertype,thenopmusthaveanon-retainablepointertype.IfTisanon-retainablepointertype,thenopmusthavearetainableo
使用ARC,我不能再将CGColorRef转换为id。我了解到我需要进行桥接类型转换。根据clangdocs:AbridgedcastisaC-stylecastannotatedwithoneofthreekeywords:(__bridgeT)opcaststheoperandtothedestinationtypeT.IfTisaretainableobjectpointertype,thenopmusthaveanon-retainablepointertype.IfTisanon-retainablepointertype,thenopmusthavearetainableo
如何转换(或创建)在Xcode4.2中使用自动引用计数(ARC)时编译和行为正确的单例类? 最佳答案 以您(应该)已经这样做的完全相同的方式:+(instancetype)sharedInstance{staticMyClass*sharedInstance=nil;staticdispatch_once_tonceToken;dispatch_once(&onceToken,^{sharedInstance=[[MyClassalloc]init];//Doanyotherinitialisationstuffhere});ret
如何转换(或创建)在Xcode4.2中使用自动引用计数(ARC)时编译和行为正确的单例类? 最佳答案 以您(应该)已经这样做的完全相同的方式:+(instancetype)sharedInstance{staticMyClass*sharedInstance=nil;staticdispatch_once_tonceToken;dispatch_once(&onceToken,^{sharedInstance=[[MyClassalloc]init];//Doanyotherinitialisationstuffhere});ret
我已经下载了iOS5SDK,发现ARC是Apple新编译器的一大特色。目前,许多第三方框架不支持ARC。我可以将ARC用于我的新代码并保持当前的保留/发布代码不变吗?ARC转换器在这里不起作用,因为某些框架,例如JSONKit,无法使用转换器将其转换为ARC。编辑:答案是将-fno-objc-arc添加到您不需要ARC的文件的编译器标志中。在Xcode4中,您可以在target->BuildPhases->CompileSources下执行此操作。 最佳答案 如何在MULTIPLE文件上禁用ARC不是很直观,有一段时间我一个一个地做