简体   繁体   中英

ios - Parse Issues in NSObjCRuntime, NSZone, and NSObject

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: 图片

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.

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.

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

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

在此输入图像描述 ,

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

在此输入图像描述

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

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.

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, (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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