【发布时间】:2016-07-08 22:34:55
【问题描述】:
更新到 Xcode 7.3 后,它会在 pod 文件中抛出错误 Cannot create __weak reference in file using manual reference counting。有人解决了这个问题吗?
【问题讨论】:
标签: objective-c xcode cocoapods
更新到 Xcode 7.3 后,它会在 pod 文件中抛出错误 Cannot create __weak reference in file using manual reference counting。有人解决了这个问题吗?
【问题讨论】:
标签: objective-c xcode cocoapods
我找到了这个。
我猜这意味着删除 __weak
https://forums.developer.apple.com/thread/38934
呃,在 MRR [手动保留释放] 下是否有过弱变量引用之类的东西? "__weak" 表示两种情况之一或两者:
无主引用(即不表示保留计数)。
归零引用(即,当引用的对象被释放时运行时归零)。
#1 不适用于 MRR,因为你只是不保留变量。
#2 也不适用于 MRR,因为运行时支持在 GC 和 ARC [自动引用计数] 中,您没有使用它们。
听起来编译器现在只是在抱怨它不能做它永远做不到的事情。 (对于应用程序委托,您将无法在运行时区分差异,因为应用程序委托通常不会被释放。)
【讨论】:
这是来自链接的 Apple 官方回答:
此问题的行为符合预期,基于以下几点:我们处于 在所有 Objective-C 语言中实现弱引用的过程 模式。由于“__weak”历来在非 ARC(和 non-GC) 语言模式,我们添加了这个错误来指出地方 语义将在未来发生变化的地方。请更新您的错误 报告,让我们知道这是否仍然是您的问题。
因此,基本上,如果您将 Pod 用于 3rd 方库,则必须删除非 ARC 中的 __weak 或等待更新。
更新@3/23
我应该研究更多关于我可以传递给编译器以绕过这些东西的标志。但从根本上说,从现在开始,您不应在非 ARC 模式下使用__weak,以避免任何意外冲突。对于 cocoapods 用户,您不需要删除 __weak 或等待更新,而是将构建设置中的 Weak References in Manual Retain Release 标志设置为 YES,就像 Lean 说的那样。希望这有帮助。
【讨论】:
将Build Settings -> Apple LLVM 7.1 - Language - Objective C -> Weak References in Manual Retain Release 设置为YES。
取自Apple Developers Forums - Xcode 7.3b4, non-arc, cannot create __weak reference。
【讨论】:
-Wall -Wextra -Wno-unused-parameter 警告标志。
只需在“Build Phases”选项卡中转到您的目标,在“Compile Sources”中查找 pod 文件,单击这些文件并添加编译器标志“-fobjc-arc”
【讨论】:
解决此问题的最佳方法是在您的 Podfile 中添加一个 post_install 脚本,将所有 pod 目标中的 Weak References in Manual Retain Release 标志设置为 yes。为此,只需将以下代码粘贴到您的 Podfile 底部即可。
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_OBJC_WEAK'] ||= 'YES'
end
end
end
有时,这样做会导致错误-fobjc-weak is not supported on the current deployment target。您可以通过添加另一个配置选项来解决这个问题,强制所有 pod 以您想要的版本为目标 (based on this answer):
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_OBJC_WEAK'] ||= 'YES'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.3'
end
end
end
【讨论】:
或将__weak 更改为__unsafeunretained。这将解决传统的问题。由于 MRC(在 xCode 4 之前 --)__weak 不在 iOS 中。
【讨论】:
FBSettings.m 中 Facebook 弱引用的解决方法
对于 Podfile,可以写一个脚本在 pod install/update 之后运行,这里有如下描述。
post_install do | installer |
classy_pods_target = installer.pods_project.targets.find {| target | target.name == 'Facebook-iOS-SDK'}
classy_pods_target.build_configurations.each do | config |
config.build_settings['CLANG_ENABLE_OBJC_WEAK'] ||= 'YES'
end
end
CLANG_ENABLE_OBJC_WEAK 怎么找到魔法的那句话。 .
【讨论】: