.dynamicType 已弃用.使用'type(of ...)'代替 [英] .dynamicType is deprecated. Use 'type(of ...)' instead

查看:32
本文介绍了.dynamicType 已弃用.使用'type(of ...)'代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新到 Xcode 8 和 iOS 10(使用旧的 Swift 语言版本).

尝试再次编译我的项目是一件痛苦的事情,即使仍然使用旧的 Swift 语法.这次我的一个函数使用 NSBundle(forClass: self.dynamicType) 但现在看来 .dynamicType 已被弃用,Xcode 甚至不想编译它.>

他的建议是使用 type(of: self) 但这也失败了.有谁知道解决方案?谢谢.

解决方案

@dfri answer 非常适合 Swift 3.

关于 Swift 2.3,我的解决方案是清理 Xcode (Command+Option+Shift+K) 并删除 ~/Library/Developer/Xcode/DerivedData 中的所有内容.问题不会立即消失,但一段时间后它会停止出现该错误.

也许这是一个错误,毕竟我们是在 8.0 中.我希望它在下一个版本中得到修复.

谢谢大家.

I've just updated to Xcode 8 and iOS 10 (using legacy Swift Language Version).

Trying to compile again my project has been an agony, even still using the old Swift syntax. This time one of my functions uses NSBundle(forClass: self.dynamicType) but now appears that .dynamicType is deprecated and Xcode doesn't even want to compile it.

His suggestion is to use type(of: self) but that fails as well. Anyone knows the solution? Thanks.

解决方案

@dfri answer works perfectly for Swift 3.

Regarding Swift 2.3, my solution was to clean Xcode (Command+Option+Shift+K) and delete everything in ~/Library/Developer/Xcode/DerivedData. The problem doesn't disappear instantly but after some time it will stop giving that error.

Maybe it's a bug, after all we are in 8.0. I hope it gets fixed in next releases.

Thank you everyone.

这篇关于.dynamicType 已弃用.使用'type(of ...)'代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆