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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11857765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:38:11  来源:igfitidea点击:

ios - Parse Issues in NSObjCRuntime, NSZone, and NSObject

ioscompiler-errorsautomatic-ref-countingaddthis

提问by soleil

I'm using AddThisto 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. I have the requisite frameworks included as well. Any ideas?

这些错误发生在 NSObjCRuntime、NSZone 和 NSObject 中。我也包含了必要的框架。有任何想法吗?

Including this image if it helps: image

如果有帮助,请包括此图像: 图片

采纳答案by soleil

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.

我刚刚把Base64Transcoder.c的文件名改成了Base64Transcoder.m,现在项目编译通过了。我不知道为什么这可以解决问题,但它有效。

回答by horacex

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:

当我尝试将 C 代码(.h 和 .c)与 Objective-C 代码混合时,我的项目遇到了同样的问题。找到问题原因:

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.

希望有帮助。

回答by Bastien

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 目标” -c”并将“其他 C++ 标志”设置为“-x Objective-c++”

this will do the trick with xCode 7.2

这将使用 xCode 7.2 解决问题

回答by gaRik

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

当我的项目包含 .cpp 文件时,我遇到了同样的问题。

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

如果 .cpp 文件不包含 ObjectiveC 框架(例如),它必须是“默认-C++ 源”类型

enter image description here,

在此处输入图片说明,

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

但如果 .cpp 文件具有 ObjectiveC 框架 - 它必须是“Objective-C++ Source”

enter image description here

在此处输入图片说明

回答by user1469569

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. The structure was this:

细节:我得到这个是因为我不小心在 C++ 类头中间接地包含了一个 Objective-C 类头。结构是这样的:

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 定义了一个 C++ 类,它可以理解 Objective 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. Later, I changed my code and included Compass.h in ActionTracker.h, which then pulled it into HelloWorld.h and I got these errors.

在我最初的设置中,HelloWorld.h 包含 ActionTracker.h,但这没关系,因为 ActionTracker.h 还没有包含 Compass.h。后来,我更改了代码并将 Compass.h 包含在 ActionTracker.h 中,然后将其拉入 HelloWorld.h 并出现这些错误。

回答by Matthys Du Toit

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".

当我尝试将 info.plist 文件从一个目录移动到另一个目录时,我遇到了同样的问题。这以某种方式触发 XCode 编辑该目标的构建阶段,并显着增加了“编译源”和“复制捆绑资源”的数量。

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)

幸运的是,我的项目有多个用于测试的目标(即 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.

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