ios - Parse Issues in NSObjCRuntime, NSZone, and NSObject
Asked Answered
P

6

41

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

Pero answered 8/8, 2012 at 4:41 Comment(4)
Are you trying to do this in a c file?Scopolamine
Not sure what you mean, but there is one .c file in the library, called Base64Transcoder.cPero
Looks like the same issue here: #7655252, but no solution. Assuming I have the one .c file, how do I work around that?Pero
The problems only arise when you try to link ObjC frameworks to C files (in my experience at least). Does Base64.c import any frameworks?Scopolamine
P
21

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.

Pero answered 8/8, 2012 at 5:28 Comment(2)
I am guessing it was. You made your c file into an objective-c file so after that importing objective-c frameworks worked. The fun part is that the .pch file is imported into all c files as well as obj-c files so if there are unprotected obj-c imports in the pch file you end up with this idiotic error message.Bailor
Unbelievable. Thanks so much.Thorpe
L
131

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.

Lewls answered 5/11, 2012 at 15:14 Comment(6)
Thank you so much, just saved me an hours long headache right here! You've got to wonder if the issue is that you're trying to import Objective-C frameworks into c code why don't they say so? Why does XCode generate cryptic error messages that are next to meaningless? Anyway, thanks!!! And yeah, I put all my imports in the .pch file inside the ifdef and it all worked.Bailor
you are welcome. that's exactly the value of this community. I got much more help from it :)Lewls
THANK YOU! Followers, also make sure to not #define NSStrings or const. NSNumbers outside of the OBJC block!Diarmuid
I don't have a PCH, so what should I do?Quentin
Thanks lot @LewlsCouching
Solved my Problem ThxAdaliah
P
21

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.

Pero answered 8/8, 2012 at 5:28 Comment(2)
I am guessing it was. You made your c file into an objective-c file so after that importing objective-c frameworks worked. The fun part is that the .pch file is imported into all c files as well as obj-c files so if there are unprotected obj-c imports in the pch file you end up with this idiotic error message.Bailor
Unbelievable. Thanks so much.Thorpe
N
19

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

Nonexistence answered 4/2, 2016 at 10:53 Comment(1)
The C++ setting worked for me, my project had no .pch files and no .c files, Xcode 7.2.1.Mentholated
B
17

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

enter image description here,

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

enter image description here

Burne answered 3/7, 2014 at 18:47 Comment(0)
B
3

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.

Bohol answered 15/6, 2014 at 5:30 Comment(0)
C
0

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.

Clothesline answered 8/8, 2012 at 4:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.