iphone - 合并 ARC 和非 ARC 文件不起作用

标签 iphone ios xcode automatic-ref-counting

一旦我将 -fno-objc-arc 标志添加到构建阶段中的一个或多个单独的文件,我的 MyProject-Prefix.pch 文件就会进入非 ARC 模式,导致 150 条警告,如“警告:没有‘分配’ 、'retain' 或 'copy' 属性被指定 - 'assign' 被假定为“被抛出。

这是编译 MyProject-Prefix.pch 的 clang 日志输出。如您所见,出现了 -fobjc-arc 标志,但后来添加了 -no-fobjc-arc,我假设它会覆盖 ARC。仅当我将 -fno-objc-arc 添加到构建阶段中的单个 .m 源文件时才会发生这种情况(每个人都得到混合 ARC 和非 ARC 文件的标准建议)。

有什么想法吗?

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c-header -arch i386 -fmessage-length=0 -std=gnu99 -fobjc-arc -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-sign-compare -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -DDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fexceptions -fasm-blocks -Wprotocol -Wdeprecated-declarations -mmacosx-version-min=10.6 -g -Wno-conversion -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -iquote /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/MyProject-generated-files.hmap -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/MyProject-own-target-headers.hmap -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/MyProject-all-target-headers.hmap -iquote /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/MyProject-project-headers.hmap -iquoteOAuth2Client -iquoteOAuth2Client/Sources -iquoteOAuth2Client/Sources/OAuth2Client -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Products/Debug-iphonesimulator/include -I../../Source/facebook-ios-sdk/src -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Products/Debug-iphonesimulator/../three20 -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Products/Debug-iphonesimulator/../../three20 -I../../Source/three20/Build/Products/three20 -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/DerivedSources/i386 -I/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProject.build/DerivedSources -F/Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Products/Debug-iphonesimulator -F/Users/steve/Desktop/MyProject/YelpAPI/Frameworks -fno-objc-arc --serialize-diagnostics /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/PrecompiledHeaders/MyProject-Prefix-eouuweehlrhtjxdsrgwseamnhnna/MyProject-Prefix.pch.dia -c /Users/steve/Desktop/MyProject/MyProject/MyProject-Prefix.pch -o /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/PrecompiledHeaders/MyProject-Prefix-eouuweehlrhtjxdsrgwseamnhnna/MyProject-Prefix.pch.pth -MMD -MT dependencies -MF /Users/steve/Library/Developer/Xcode/DerivedData/MyProject-ajtusdfivjqtabgvzfuzqifdjuis/Build/Intermediates/PrecompiledHeaders/MyProject-Prefix-eouuweehlrhtjxdsrgwseamnhnna/MyProject-Prefix.pch.d

最佳答案

这只是意料之中的事情。您的 .pch 文件很可能包含一些在非 ARC 模式下编译时会导致警告的定义。很可能非 arc 编译文件也会使用预编译头文件,所以 .pch 文件中的头文件应该可以在 ARC 和非 ARC 模式下编译(毕竟,PCH 机制是语义上等同于将 .pch 文件的 #imports 放入每个 .m 文件中)。

我会说这是 XCode 的一个错误,如果它在所有非 ARC 编译文件都被明确排除在 PCH 编译模型之外时仍然给出这些警告。显然你不能在 XCode 下关闭对单个文件的预编译头文件的使用(就像你可以使用 MS 的 VisualC++ 那样),所以我能给你的唯一建议是在你的 .pch 文件兼容 ARC 和非 ARC 编译。

关于iphone - 合并 ARC 和非 ARC 文件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10892487/

相关文章:

ios - 核心数据实体已创建但属性未保存

xcode - Apple TV无线调试无法连接

iphone - Xcode——将一个静态库嵌入到另一个静态库中?

iphone - 有没有办法在 Xcode 的 resources 文件夹中创建子文件夹?

iphone - 如何从 UITableView 设置 scrollView 委托(delegate)?

iphone - CALayers 没有在其 UIView 的边界更改时调整大小。为什么?

xcode - 是否可以下载旧版本的 XCode?

iphone - 导航栏上有超过 1 个 rightBarButtonItem

ios - 如何将我的文本字段设为线而不是框?

ios - 未找到应用内购买产品