How to create an Empty Application in Xcode without Storyboard
Xcode6 has removed the Empty Application template when creating a new project. How can we create an empty application (without Storyboard) in Xcode6 and above, like in earlier versions?
删除 Info.plist 中的“ Main Storyboard file base name”属性
在 Info.plist 中删除“ Launch screen interface file base name”属性
添加“[ app name ]-Prefix.pch”文件到包含内容的支持文件:
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
add "$SRCROOT/$PROJECT_NAME/[pch file name]" to project settings -> Build Settings -> Apple LLVM 6.0 - Language -> "Prefix Header"
add "YES" to to project settings -> Build Settings -> Apple LLVM 6.0 - Language -> "Precompile Prefix Header"
open "Image.xcassets" and add LaunchImage
build the project, then there will be a warning about missing default launch image, just press on the warning and select to add the default,
this will add "Default-568h@2x"
OR - If you want to use splash images from "Images.xcassets", go to the project settings -> TARGETS -> General -> in "Launch Images Source" choose to use asset catalog, it will create a new one, you can choose then, which to use as asset catalog from the existing.
First of all you need delete Main.storyboard in Project navigator menu.
Then delete row Main storyboard file base name in Info.plist.
And don't forgot delete cell Main Interface (just remove Main) in your Project Target - General - Deployment Info.
This step is important and it was not in previous versions of Xcode and Swift. In Info.plist go to: Application Scene Manifest → Scene Configuration → Application Session Role → Item 0 and delete here Storyboard.name row.
After that steps go to SceneDelegate and in function scene write the next:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
}
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
到
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).x
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = ViewController()
self.window = window
window.makeKeyAndVisible()
}
}