ios - Parse Issues in NSObjCRuntime, NSZone, and NSObject

梦想的初衷 提交于 2019-11-26 10:23:38

问题


I\'m using AddThis to add sharing options in my iOS app.

I have imported the classes and added the -fno-objc-arc flag to all the imported classes since they don\'t use ARC.

However, when I try to run the app I get a slew of Parse Issues such as:

Expected identifier or \'(\'
Unknown type name \'NSString\'
Unknown type name \'Protocol\'
...

These errors occur in NSObjCRuntime, NSZone, and NSObject. I have the requisite frameworks included as well. Any ideas?

Including this image if it helps: \"image\"


回答1:


I had the same issue on my project when I was trying to mix C code (.h and .c) with Objective-C code. Found the reason of the issue:

Check your .pch file to make sure every Objective-C framework #import (such as #import <UIKit/UIKit.h>) is enclosed in:

#ifdef __OBJC__

#endif

If they're outside of this conditional scope, the compiler will try to import Objective-C frameworks into C source code.

Hope that helps.




回答2:


I just changed the filename of Base64Transcoder.c to Base64Transcoder.m, and now the project compiles. I have no idea why this fixes the problem, but it works.




回答3:


I have had the same problem when my project contained .cpp files.

If .cpp file doesn't contain ObjectiveC frameworks(e.g. ) it has to 'Default-C++ Source' type

,

but if .cpp file has ObjectiveC frameworks - it must be as 'Objective-C++ Source'




回答4:


I had the same issue, using C and C++ code with objective C, and i doesnt have a .pch The easiest solution was to go into your build settings -> Custom Compiler Flags and set the "Other C Flags" to "-x objective-c" and set the "Other C++ Flags" to "-x objective-c++"

this will do the trick with xCode 7.2




回答5:


TLDR: if your PCH file is OK, look through your CPP file headers to see if you've accidentally included any headers for Objective C objects.

The Details: I got this because I had accidentally included an Objective-C class header in a C++ class header, indirectly. The structure was this:

Compass.h defined a pure Objective C class.

ActionTracker.h defined a C++ class that understood Objective C constructs (via ActionTracker.mm).

HelloWorld.h defined a purely C++ class.

In my original setup, HelloWorld.h included ActionTracker.h, but this was OK as ActionTracker.h didn't yet contain Compass.h. Later, I changed my code and included Compass.h in ActionTracker.h, which then pulled it into HelloWorld.h and I got these errors.




回答6:


I had this same problem when I tried to move the info.plist file from one directory to another. This somehow triggered XCode to edit the build phases for that target and significantly increased the amount of "Compile Sources" and "Copy Bundle Resources".

Luckily my project has multiple targets that I use for testing, (i.e. App Demo, App Dev, App Local, App 1.1, App 1.2 etc)

So I just duplicated one of the unaffected targets and renamed it (also renamed the bundle identifier and the build scheme) and this obviously fixed the problem for me since it's not the whole project that was affected but only that specific target.

If you want to try my solution, try to create a new target from scratch, or duplicate and rename any of your un-affected targets.



来源:https://stackoverflow.com/questions/11857765/ios-parse-issues-in-nsobjcruntime-nszone-and-nsobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!