teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

Fix typo

2019/10/03 03:24

投稿

hayabusabusash
hayabusabusash

スコア776

answer CHANGED
@@ -196,6 +196,7 @@
196
196
 
197
197
  ![info.plist](ecbc47ffd58bc39e91cd339f7a0d4aaf.png)
198
198
 
199
- これで一応エラーなしで起動することができました
199
+ これで一応エラーなしで起動することができました
200
+
200
201
  正直まだ正しい対応なのか確証が持てていないので、もう少し調査する必要があるかもしれません。
201
202
  曖昧な回答しかできず申し訳ありません。

1

SceneDelegateについて追記

2019/10/03 03:24

投稿

hayabusabusash
hayabusabusash

スコア776

answer CHANGED
@@ -2,4 +2,200 @@
2
2
 
3
3
  `Main`になっていませんか?
4
4
 
5
- ![イメージ説明](957777c28ae6b316ad5a26d939a1854c.png)
5
+ ![イメージ説明](957777c28ae6b316ad5a26d939a1854c.png)
6
+
7
+ ## 追記(2019/10/03)
8
+ Xcode11でiOS13のターゲットのプロジェクトを作成した場合は`SceneDelegate`や`AppDelegate`はそのままで問題ないと思います。
9
+ [参考にさせていただいたサイト](https://tech.yappli.io/entry/scenedelegate)をみたところ
10
+
11
+ > 「ライフサイクルイベント」が発生したときは SceneDelegate か AppDelegate のどちらかのメソッドしか呼ばれない
12
+ iOS 13 かつ SceneDelegate が使用されている場合は SceneDelegate が
13
+ それ以外では AppDelegate が
14
+
15
+ となっていたので、
16
+ ちょっと自信がありませんが、上記の対応が必要になるのは**Xcode11でiOS12.x以下をターゲットとしたプロジェクトを作成した時**だと思います。
17
+
18
+ 手元で以下のようなコードで生成したViewControllerをルートにして実行することができたので、
19
+ 参考として貼っておきます。
20
+
21
+ ```Swift
22
+ // CodeViewController
23
+ import UIKit
24
+
25
+ final class CodeViewController: UIViewController {
26
+
27
+ // MARK: - UI
28
+
29
+ lazy var titleLabel: UILabel = {
30
+ let label = UILabel()
31
+ label.translatesAutoresizingMaskIntoConstraints = false
32
+ label.font = UIFont.boldSystemFont(ofSize: 18)
33
+ label.text = "Title"
34
+ return label
35
+ }()
36
+
37
+ lazy var descLabel: UILabel = {
38
+ let label = UILabel()
39
+ label.translatesAutoresizingMaskIntoConstraints = false
40
+ label.font = UIFont.systemFont(ofSize: 15)
41
+ label.textColor = UIColor.lightGray
42
+ label.text = "Desc"
43
+ return label
44
+ }()
45
+
46
+ lazy var button: UIButton = {
47
+ let button = UIButton()
48
+ button.translatesAutoresizingMaskIntoConstraints = false
49
+ button.setTitle("Button", for: .normal)
50
+ button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 15)
51
+ button.titleLabel?.textColor = UIColor.white
52
+ button.backgroundColor = UIColor.blue
53
+ button.layer.cornerRadius = 4.0
54
+ return button
55
+ }()
56
+
57
+ // MARK: - Lifecycle
58
+
59
+ override func viewDidLoad() {
60
+ super.viewDidLoad()
61
+
62
+ // UI
63
+ view.backgroundColor = .white
64
+ view.addSubview(titleLabel)
65
+ view.addSubview(descLabel)
66
+ view.addSubview(button)
67
+ setupLayout()
68
+ }
69
+ }
70
+
71
+ // MARK: - AutoLayout
72
+ extension CodeViewController {
73
+
74
+ func setupLayout() {
75
+ // titleLabel
76
+ NSLayoutConstraint.activate([
77
+ titleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 0),
78
+ titleLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 0)
79
+ ])
80
+
81
+ // descLabel
82
+ NSLayoutConstraint.activate([
83
+ descLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8),
84
+ descLabel.centerXAnchor.constraint(equalTo: titleLabel.centerXAnchor, constant: 0)
85
+ ])
86
+
87
+ // button
88
+ NSLayoutConstraint.activate([
89
+ button.topAnchor.constraint(equalTo: descLabel.bottomAnchor, constant: 16),
90
+ button.centerXAnchor.constraint(equalTo: descLabel.centerXAnchor, constant: 0),
91
+ button.widthAnchor.constraint(equalToConstant: 88),
92
+ button.heightAnchor.constraint(equalToConstant: 44)
93
+ ])
94
+ }
95
+ }
96
+
97
+ ```
98
+
99
+ AppDelegateはプロジェクト生成時のままです。
100
+
101
+ ```Swift
102
+ // AppDelegate
103
+ import UIKit
104
+
105
+ @UIApplicationMain
106
+ class AppDelegate: UIResponder, UIApplicationDelegate {
107
+
108
+
109
+
110
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
111
+ // Override point for customization after application launch.
112
+ return true
113
+ }
114
+
115
+ // MARK: UISceneSession Lifecycle
116
+
117
+ func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
118
+ // Called when a new scene session is being created.
119
+ // Use this method to select a configuration to create the new scene with.
120
+ return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
121
+ }
122
+
123
+ func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
124
+ // Called when the user discards a scene session.
125
+ // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
126
+ // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
127
+ }
128
+
129
+
130
+ }
131
+ ```
132
+
133
+ SceneDelegateが`window`プロパティを持っているようなので、
134
+ ここでrootViewControllerの設定をしました。
135
+ 色々変わっていたので[こちら](https://qiita.com/rc_code/items/795ddadb98dfa09d10e6)を参考にさせていただきました。
136
+
137
+ ```Swift
138
+ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
139
+
140
+ var window: UIWindow?
141
+
142
+
143
+ func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
144
+ // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
145
+ // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
146
+ // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
147
+ guard let _ = (scene as? UIWindowScene) else { return }
148
+
149
+ if let windowScene = scene as? UIWindowScene {
150
+ let window = UIWindow(windowScene: windowScene)
151
+ window.rootViewController = CodeViewController(nibName: nil, bundle: nil)
152
+ self.window = window
153
+ window.makeKeyAndVisible()
154
+ }
155
+ }
156
+
157
+ func sceneDidDisconnect(_ scene: UIScene) {
158
+ // Called as the scene is being released by the system.
159
+ // This occurs shortly after the scene enters the background, or when its session is discarded.
160
+ // Release any resources associated with this scene that can be re-created the next time the scene connects.
161
+ // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
162
+ }
163
+
164
+ func sceneDidBecomeActive(_ scene: UIScene) {
165
+ // Called when the scene has moved from an inactive state to an active state.
166
+ // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
167
+ }
168
+
169
+ func sceneWillResignActive(_ scene: UIScene) {
170
+ // Called when the scene will move from an active state to an inactive state.
171
+ // This may occur due to temporary interruptions (ex. an incoming phone call).
172
+ }
173
+
174
+ func sceneWillEnterForeground(_ scene: UIScene) {
175
+ // Called as the scene transitions from the background to the foreground.
176
+ // Use this method to undo the changes made on entering the background.
177
+ }
178
+
179
+ func sceneDidEnterBackground(_ scene: UIScene) {
180
+ // Called as the scene transitions from the foreground to the background.
181
+ // Use this method to save data, release shared resources, and store enough scene-specific state information
182
+ // to restore the scene back to its current state.
183
+ }
184
+
185
+
186
+ }
187
+ ```
188
+
189
+ この状態で`Main`のStoryboardを削除したところ質問者様と同じ
190
+
191
+ > Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle NSBundle
192
+
193
+ 上記のエラーが出たので、
194
+ Xcodeの`Main Interface`を空にして、
195
+ info.plistの`Scene Configuration`の`Storyboard Name`の項目を削除しました。
196
+
197
+ ![info.plist](ecbc47ffd58bc39e91cd339f7a0d4aaf.png)
198
+
199
+ これで一応エラーなしで起動することができました、
200
+ 正直まだ正しい対応なのか確証が持てていないので、もう少し調査する必要があるかもしれません。
201
+ 曖昧な回答しかできず申し訳ありません。