Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

refactoring to arc results in "synthesize of 'weak' property is only allowed in arc or gc mode"

Tags:

iphone

ios4

ios5

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. at this point, i've decided to try refactoring in xcode and an error occurs. 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.

I am puzzeled - i am using arc and it complains that it is only allowed in 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)

like image 782
unpluggedk Avatar asked Sep 15 '12 02:09

unpluggedk


2 Answers

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. 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.

like image 87
AppHandwerker Avatar answered Nov 04 '22 02:11

AppHandwerker


I had the same symptom using Xcode 4.6.3 targeting iOS 6.1. 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”).

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.

I got around the issue by setting the property to 'strong' and converting that class to ARC via the Refactor menu. 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. I think the moral of the story is that including your whole project in the refactoring might be safer...

like image 30
Buzzwig Avatar answered Nov 04 '22 03:11

Buzzwig