ARC technology isn't being used in my project. I'm trying to add SBJson library to it. I set -fobjc-arc flag for all files which have SBJson prefix, but during compilation process ARC semantic issue (Pointer to non-const type 'id' with no explicit ownership) appears in one class header, which is not related to SBJSon. Why doesn't it work?
Line with error:
id *_controls;
I cannot show you my code because of commercial license of project, I appreciate your understanding.
Project compilation goes normally when I use older version of this library (without ARC).
The issue is that you are mixing an ARC violating construct into ARC'd files through inclusion. You can't apply
-fno-objc-arc
to a single header file because that doesn't make sense.Since it is in a header file, you will either need to use an #if pragma to switch between behaviors depending on whether an ARC or non-ARC .m file is being compiled.
A better solution, however, is to eliminate the issue entirely for both ARC and non-ARC. Given that declaration, it pretty much has to be an instance variable (though it could be in a struct).
If it is an ivar, get rid of the declaration entirely. Either expose it through
@property
or move it to the.m
file if it does not need to be exposed in your public API. Given the type, it really should be a private implementation detail with public API that makes accessing the contents a bit less pointer-magic.In general, using C language arrays -- arrays of pointers -- to store Objective-C types is highly discouraged. If
_controls
does need to be exposed as a publicly accessible thing (public to the other classes in your project), then refactor your code to use a collection class (i.e. typically an exposedNSArray*
getter with an internal-onlyNSMutableArray*
backing store -- likesubviews
onUIView
, for example).As you said in the comments, the precompiled header file includes a class header file that is not meant to be compiled with ARC. This is causing the error, because the precompiled header is also included by all SBJson files that are compiled with ARC.
I would suggest that you remove that class header file from the .pch file and include it only from the non-ARC source files, where needed.