
什么是 swift 相当于下一个代码:[NSBundle bundleForClass:[self class]] ?
目前只知道 Swift = 2.x NSBundle(forClass: self.dynamicType) Swift 3.x Bundle(for: type(of: self))
但是 Swift4 之后要怎么写呢?请教各位 iOS 大神
1 jameskuk 2019 年 7 月 11 日 你写的 swift3 的 Bundle(for: type(of: self)) 不能再 swift4 上用了吗? |
2 maxCham OP 不能了 |
3 jameskuk 2019 年 7 月 11 日 那你试试 Bundle(for: self.classForCoder()) |
4 maxCham OP 我的 type 系一个自定的类型,swift3 时这样写没问题;转 swift4 时就会报这个 type 是 Cannot call value of non-function type |
5 maxCham OP Bundle(for: self.classForCoder()) 这个肯定对,因为传进去的就是要 anyClass; 但是既然是 anyClass,为什么我这个自定义的 type 就不行了呢? |
6 maxCham OP 我的 type 也是这样的一个 class 来的:class var typeList: DisplayType {} |
7 maxCham OP public enum DisplayType { } public final class Display { class var typeList: DisplayType { } } |
8 maxCham OP let type = Display. typeList let bundle = Bundle(for: type(of: self)) 就会有错 |
9 momocraft 2019 年 7 月 11 日 这个帖子第一行是英文机翻出来的吗? |
10 finab 2019 年 7 月 11 日 AnyClass 其实是 AnyObject.Type 如果你要把 typeList 当做 AnyClass 你需要这样定义 var typeList: DisplayType.Type |
11 maxCham OP 哈哈,不是不是,只是搜索到一个帖子的标题,内容都是一样的,所以走来 V 站问问大神,交流交流 |
12 maxCham OP 谢谢大神们,我找到了,原来不是语法问题;是我理解错了,用会 Bundle(for: self.classForCoder())就可以了 |
13 onevcat 2019 年 7 月 11 日 大概这样就行了? Bundle(for: Self.self) |