简体   繁体   English

重构为弧导致“仅在弧或gc模式下允许合成'弱'属性”

[英]refactoring to arc results in “synthesize of 'weak' property is only allowed in arc or gc mode”

i am using xcode 4.4.1 for iOS target 5.1 i've started my project using ARC, and in the middle of the project I've added some non-arc thirdparty source to my project. 我将xcode 4.4.1用于iOS目标5.1我已经使用ARC启动了我的项目,并且在项目的中间,我向项目中添加了一些非弧形的第三方源代码。 at this point, i've decided to try refactoring in xcode and an error occurs. 在这一点上,我决定尝试在xcode中进行重构,并且发生错误。 it comes from one of my original source code. 它来自我的原始源代码之一。

i have a property of (nonatomic, weak) and i've synthesized it ==> synthesize of 'weak' property is only allowed in ARC or GC mode. 我具有(非原子的,弱的)属性,并且已经合成==>“弱”属性的合成仅在ARC或GC模式下允许。

I am puzzeled - i am using arc and it complains that it is only allowed in arc?? 我很困惑-我使用的是arc,它抱怨只允许在arc中使用?

At the moment, i've refactored the thirdparty app from other project and copied it for my project to work, but the above is a question I'd still like to understand why . 目前,我已经从其他项目中重构了第三方应用程序,并将其复制到我的项目中,但是上面的问题我仍然想理解为什么。 Thanks! 谢谢! (by the way, when i do convert to arc, it says that the target currently uses ARC) (顺便说一句,当我确实转换为圆弧时,它表示目标当前使用ARC)

It sounds like the issue is you've already set it up as an ARC project and your are for some reason trying to convert it again. 听起来问题是您已经将其设置为ARC项目,并且由于某种原因而试图再次进行转换。 I can only assume that the process doesn't expect therefore weak references at this stage. 我只能假设该过程不会在此阶段期望弱引用。 If you set them to Assign then convert to ARC you will see that it then suggests you change them to weak. 如果将它们设置为Assign,然后转换为ARC,您会看到它建议您将它们更改为弱。

I had the same symptom using Xcode 4.6.3 targeting iOS 6.1. 使用针对iOS 6.1的Xcode 4.6.3有相同的症状。 I brought in a non-ARC class from another project and converted it via the Refactor menu only to have subsequent builds fail on a pre-existing class with the error you saw (“synthesize of 'weak' property is only allowed in arc or gc mode”). 我从另一个项目中引入了一个非ARC类,并通过“重构”菜单对其进行了转换,以使随后的构建在先前存在的类上失败,并出现错误(“ arge或gc仅允许合成'weak'属性)模式”)。

The project properties clearly said it was still an ARC project but the compiler seemed to have forgotten this was the case for the class in question. 项目属性明确表示它仍然是ARC项目,但编译器似乎已经忘记了所涉及类的情况。

I got around the issue by setting the property to 'strong' and converting that class to ARC via the Refactor menu. 我通过将属性设置为“ strong”并通过“重构”菜单将该类转换为ARC来解决了这个问题。 Unsurprisingly it told me no changes were necessary but did offer a Save button which I clicked. 毫不奇怪,它告诉我没有必要进行任何更改,但确实提供了我单击的“保存”按钮。 I was then able to change the property back to 'weak' and compile the project. 然后,我能够将属性更改回“弱”并编译项目。 (I'm presuming some metadata got out of synch somewhere along the way.) (我认为在此过程中某处某些元数据不同步。)

EDIT: I eventually had to 'Refactor' other ARC-compliant classes to ARC as although they compiled they generated warnings and caused crashes in my app. 编辑:我最终不得不将其他ARC兼容类“重构”到ARC,尽管它们编译它们会生成警告并导致我的应用程序崩溃。 I think the moral of the story is that including your whole project in the refactoring might be safer... 我认为这个故事的寓意是,将您的整个项目包括在重构中可能会更安全。

instead use: 改为使用:

@property(nonatomic,assign)

*note - This is not the same as weak, but very similar. *注意-这与弱点不一样,但是非常相似。 Weak also sets the object to nil, assign does not. 弱也将对象设置为nil,assign不设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM