1
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// step 1. check the device
var idiom = UIDevice.currentDevice().userInterfaceIdiom
// step 2. take a storyboard variable
var storyBoard:UIStoryboard? = nil
// step 3. load appropriate storyboard file
if idiom == UIUserInterfaceIdiom.Phone {
storyBoard = UIStoryboard(name: "Main", bundle: nil)
} else {
storyBoard = UIStoryboard(name: "Main_iPad", bundle: nil)
}
// step 4. un-box storyboard to sb variable
if let sb = storyBoard {
// step 5. create new window
window = UIWindow(frame: UIScreen.mainScreen().bounds)
// step 6. generates error :('Cannot assign to the result of this expression'
self.window?.rootViewController?.storyboard = sb
// step 7. make key window & visible
window?.makeKeyAndVisible()
}
return true
}
我在步骤6中遇到错误!由于我是新手,我发现在这里编写代码有点困难。Swift - 以编程方式加载故事板