2
votes

I am finally trying to convert my ios project to ARC. there is several files that I do not want to convert to ARC, so I have added the "-fno-objc-arc" flag to build phase -> compile sources to the corresponding *.m file.

However, when I try to edit -> refactor -> convert to ARC, I am getting a "Cannot Convert to Objective-C ARC: Xcode found 3 issues that prevent conversion from proceeding. Fix all ARC readiness issues and try again." error

the errors are all on the *.h file for which I have added the -fno-objc-arc to for the corresponding *.m file... Do I have to add the flag to the *.h file too? If so, where can I find it?

Thanks!

EDIT So I read the error more clearly. the file i am having issue with is JSONKit.h. The errors are not generated in JSONKit.m, but other classes that I wrote which imports JSONKit.h So is the only solution to add the -fno-objc-arc flag to my own classes that imports JSONKit.h? Thanks

1
Sounds like a design error on your side. Could you post one of the errors and the corresponding header entry? - Till
It seems like you are mixing metaphors by adding he -fno... flag before converting to ARC. If you have files you want to keep "normal", why not remove them from your target, refactor, then add them back and add the flag? - David H
hi I made an edit. the line of code highlighted for ARC Restrictions error is simply "#import "JSONKit.h"". The same line on JSONKit.m does not have this error since I added the -fno-objc-arc to JSONKit.m. So must I add the flag to the classes I created which import JSONKit.h? I might have more classes in the future that relies on JSONKit; that would not be ideal... thx - minovsky
Thanks David, I do want to convert all my self-written classes to ARC, just that some of them (and more in the future probably) imports JSONKit.h which is not ARC compliant and I do not want to mess with JSONKit myself... - minovsky
I used that JSONKit myself in an all ARC project. I think I had converted to ARC before adding it, and when I added it it was the ONLY file I had to use the -fno flag with. I think my suggestion will work for you. - David H

1 Answers

1
votes

temporary getaround (unless someone can suggest better)

I have having error with the following in JSONKit.h

typedef struct {
   JKParseOptionFlags  parseOptionFlags;
   JKConstBuffer       stringBuffer;
   size_t              atIndex, lineNumber, lineStartIndex;
   size_t              prev_atIndex, prev_lineNumber, prev_lineStartIndex;
   int                 errorIsPrev;
   JKParseToken        token;
   JKObjectStack       objectStack;
   JKTokenCache        cache;
   JKObjCImpCache      objCImpCache;
   NSError            *error;
 } JKParseState;

the error is on the NSError line - "ARC forbids Objective-C objects in structs or unions"

following another stackoverflow question, I changed the line to

__unsafe_unretained NSError *error;

and it compiles... seems to work ok so far