我们使用下面的代码来引用我们为xib和images等资源添加的包,但是我不确定在swift中访问它们的代码是什么。
NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:@"DTPinLockController" ofType:@"bundle"];
NSBundle *resourceBundle = [NSBundle bundleWithPath:resourceBundlePath];
任何人都可以将此转换为swift 1.2代码吗?
答案 0 :(得分:0)
Swift中的构造函数与Objective-C略有不同。试试这个:
let path = NSBundle.mainBundle().pathForResource("DTPinLockController", ofType: "bundle")!
let bundle = NSBundle(path: path)
然后在该捆绑包内的NIB中加载UIViewController
:
let controller = UIViewController(nibName: "MyViewController", bundle: bundle) as! MyViewController
查看Apple documentation以获取完整参考。顶部有一个选择器,可让您在Swift和Objective-C之间切换。