在更新到Xcode 7.3之后,它会在pod文件中引发错误Cannot create __weak reference in file using manual reference counting
。有没有人解决过这个问题?Xcode 7.3无法在使用手动引用计数的文件中创建__weak引用
回答
Set Build Settings -> Apple LLVM 7.1 - Language - Objective C -> Weak References in Manual Retain Release
to YES
。
从Apple Developers Forums - Xcode 7.3b4, non-arc, cannot create __weak reference服用。
我已经找到了。
我猜它的意思删除__weak
https://forums.developer.apple.com/thread/38934
Erm, was there ever such a thing as a weak variable reference under MRR [manual retain-release]? "__weak" means one or both of two things:
An unowned reference (i.e. not representing a retain count).
A zeroing reference (i.e. that the runtime zeroes when the referenced object is deallocated).
#1 doesn't apply to MRR, because you just don't retain the variable anyway.
#2 doesn't apply to MRR either, because the runtime support is in GC and ARC [automatic reference counting], which you're not using.
It sounds like the compiler is now just complaining that it can't do what it could never do. (And in the case of an app delegate, you wouldn't be able to tell the difference at run-time, since the app delegate generally is never deallocated.)
这是官方的回答从苹果公司的链接:
This issue behaves as intended based on the following: We are in the process of implementing weak references in all Objective-C language modes. Since “__weak” has historically been ignored in non-ARC (and non-GC) language modes, we’ve added this error to point out places where the semantics will change in the future. Please update your bug report to let us know if this is still an issue for you.
所以基本上,如果你使用的吊舱对第三方库,您必须删除非ARC中的__weak或等待更新。
更新@ 3/23
我应该研究更多关于我可以通过以编译绕过这些还挺充塞标志。但从根本上说,从现在开始,您不应该在非ARC模式下使用__weak
以避免任何意外冲突。对于cocoapods用户,您不需要删除__weak
或等待更新,但将生成设置中的Weak References in Manual Retain Release
标志设置为YES,如Lean所述。希望这个帮助。
请注意,如果您当前正在运行pod install/pod更新,那么对于每个pod目标,手动保留发布中的弱引用设置为NO - 并且您将不得不再次编辑构建设置。 – Damo
就跳转到你的目标在“构建阶段”选项卡中寻找在“编译来源”荚文件,点击这些文件,并添加编译标志“-fobjc弧”
解决这是最好的方法将post_install
脚本添加到您的Podfile,将Weak References in Manual Retain Release
标志设置为yes
在您的所有Pod目标中。要做到这一点,只需将以下代码粘贴到您的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
。您可以解决通过添加其他配置选项,迫使所有的吊舱的目标,你想要的版本(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,可以编写一个脚本吊舱后,运行安装/更新,介绍了以下那里。
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如何找到这个魔法字的那个。 。
很好的建议,谢谢! – HiveHicks
只是一个说明:看起来像FB已经改变了v3.24.4中的违规行,对于3.x版本行。 (不知道4.x系列,但现在看起来不像它。) –
- 1. 致命错误:无法使用Objective Sharpie创建__weak引用
- 2. 无法使用JAVA API创建索引
- 3. Xcode:无法创建快照 - 此文件不存在索引
- 4. Xcode - 无法禁用索引
- 5. 创建文件引用
- 6. 引用xcode中的ios计数
- 7. 无法在Alamofire response.result.value中使用NSURL! Swift,xcode 7.3
- 8. 文件无法在mac上使用xcode创建目录
- 9. 不使用特定文件上的自动引用计数
- 10. Visual Studio - dll的引用自动创建在bin文件夹中
- 11. 无法引用ASP.NET API中的文件
- 12. __weak和__block引用有什么区别?
- 13. 无法启动模拟器的Xcode 7.3
- 14. 自动__weak引用错误,但为iOS 5构建
- 15. 创建Images.xcassets文件引用到图像使用xcodeproj
- 16. Xcode中的错误:无法引用对重载函数的引用
- 17. 无法创建webdriver对象引用
- 18. 无法创建静态引用错误
- 19. 创建它时无法引用GraphQLObjectType
- 20. 无法使用Spring MongoTemplate在Azure DocumentDB中创建索引
- 21. 无法使用Mongodb协议在Azure DocumentDb中创建索引
- 22. 在java中创建动态引用
- 23. 谷歌云计算引擎 - 无法在php文件中使用mysqli函数
- 24. 在Rust中只使用引用计数
- 25. 在方法中创建弱引用
- 26. 在Xcode中使用设备UDID在Xcode中创建.app文件
- 27. 在Xcode上使用C++创建文件
- 28. 在XML中创建引用
- 29. 使用OpenSSL与XCode 7.3
- 30. 为某些文件禁用自动引用计数
我以为会有一个标志为它大声笑感谢 – REALFREE
这仍然不适用于我:(可能会有另一个编译器标志覆盖此设置,我可能已启用?我有这些'--Wall -Wextra -Wno -unused-parameter' Warning flags enabled。 – Kdawgwilk
@Kdawgwilk你确定你正确地打开该标志?如果它在你的项目中,你可以简单地删除__weak关键字tho。我没有尝试,但你也可以尝试打开Pod中的标志项目如果您正在使用Pod – REALFREE