简体   繁体   English

ios - NSObjCRuntime,NSZone和NSObject中的解析问题

[英]ios - Parse Issues in NSObjCRuntime, NSZone, and NSObject

I'm using AddThis to add sharing options in my iOS app. 我正在使用AddThis在我的iOS应用中添加共享选项。

I have imported the classes and added the -fno-objc-arc flag to all the imported classes since they don't use ARC. 我已导入类并将-fno-objc-arc标志添加到所有导入的类中,因为它们不使用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. 这些错误发生在NSObjCRuntime,NSZone和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. 当我尝试将C代码(.h和.c)与Objective-C代码混合时,我在项目中遇到了同样的问题。 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: 检查.pch文件以确保每个Objective-C框架#import(例如#import <UIKit/UIKit.h> )都包含在:

#ifdef __OBJC__

#endif

If they're outside of this conditional scope, the compiler will try to import Objective-C frameworks into C source code. 如果它们不在此条件范围内,编译器将尝试将Objective-C框架导入C源代码。

Hope that helps. 希望有所帮助。

I just changed the filename of Base64Transcoder.c to Base64Transcoder.m, and now the project compiles. 我刚刚将Base64Transcoder.c的文件名更改为Base64Transcoder.m,现在项目编译。 I have no idea why this fixes the problem, but it works. 我不知道为什么这会解决问题,但它确实有效。

I have had the same problem when my project contained .cpp files. 当我的项目包含.cpp文件时,我遇到了同样的问题。

If .cpp file doesn't contain ObjectiveC frameworks(eg ) it has to 'Default-C++ Source' type 如果.cpp文件不包含ObjectiveC框架(例如),则必须使用“Default-C ++ Source”类型

在此输入图像描述 ,

but if .cpp file has ObjectiveC frameworks - it must be as 'Objective-C++ Source' 但如果.cpp文件有ObjectiveC框架 - 它必须是'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++" 我有同样的问题,使用C和C ++代码与目标C,我没有.pch最简单的解决方案是进入您的构建设置 - >自定义编译器标志并将“其他C标志”设置为“-x objective -c“并将”其他C ++标志“设置为”-x objective-c ++“

this will do the trick with xCode 7.2 这将通过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. TLDR:如果你的PCH文件没问题,请查看你的CPP文件标题,看看你是否意外地包含了Objective C对象的任何标题。

The Details: I got this because I had accidentally included an Objective-C class header in a C++ class header, indirectly. 细节:我得到了这个,因为我不小心间接地在C ++类头中包含了一个Objective-C类头。 The structure was this: 结构是这样的:

Compass.h defined a pure Objective C class. Compass.h定义了一个纯粹的Objective C类。

ActionTracker.h defined a C++ class that understood Objective C constructs (via ActionTracker.mm). ActionTracker.h定义了一个理解Objective C结构的C ++类(通过ActionTracker.mm)。

HelloWorld.h defined a purely C++ class. HelloWorld.h定义了一个纯C ++类。

In my original setup, HelloWorld.h included ActionTracker.h, but this was OK as ActionTracker.h didn't yet contain Compass.h. 在我的原始设置中,HelloWorld.h包含ActionTracker.h,但这没关系,因为ActionTracker.h还没有包含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. 后来,我更改了我的代码并在ActionTracker.h中包含了Compass.h,然后将其拉入HelloWorld.h并得到了这些错误。

I had this same problem when I tried to move the info.plist file from one directory to another. 当我尝试将info.plist文件从一个目录移动到另一个目录时,我遇到了同样的问题。 This somehow triggered XCode to edit the build phases for that target and significantly increased the amount of "Compile Sources" and "Copy Bundle Resources". 这以某种方式触发了XCode编辑该目标的构建阶段,并显着增加了“编译源”和“复制捆绑资源”的数量。

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) 幸运的是,我的项目有多个用于测试的目标,(即App Demo,App Dev,App Local,App 1.1,App 1.2等)

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. 如果您想尝试我的解决方案,请尝试从头开始创建新目标,或复制并重命名任何未受影响的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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