回答編集履歴

2

Fix typo

2019/10/03 03:24

投稿

hayabusabusash
hayabusabusash

スコア767

test CHANGED
@@ -394,7 +394,9 @@
394
394
 
395
395
 
396
396
 
397
- これで一応エラーなしで起動することができました
397
+ これで一応エラーなしで起動することができました
398
+
399
+
398
400
 
399
401
  正直まだ正しい対応なのか確証が持てていないので、もう少し調査する必要があるかもしれません。
400
402
 

1

SceneDelegateについて追記

2019/10/03 03:24

投稿

hayabusabusash
hayabusabusash

スコア767

test CHANGED
@@ -7,3 +7,395 @@
7
7
 
8
8
 
9
9
  ![イメージ説明](957777c28ae6b316ad5a26d939a1854c.png)
10
+
11
+
12
+
13
+ ## 追記(2019/10/03)
14
+
15
+ Xcode11でiOS13のターゲットのプロジェクトを作成した場合は`SceneDelegate`や`AppDelegate`はそのままで問題ないと思います。
16
+
17
+ [参考にさせていただいたサイト](https://tech.yappli.io/entry/scenedelegate)をみたところ
18
+
19
+
20
+
21
+ > 「ライフサイクルイベント」が発生したときは SceneDelegate か AppDelegate のどちらかのメソッドしか呼ばれない
22
+
23
+ iOS 13 かつ SceneDelegate が使用されている場合は SceneDelegate が
24
+
25
+ それ以外では AppDelegate が
26
+
27
+
28
+
29
+ となっていたので、
30
+
31
+ ちょっと自信がありませんが、上記の対応が必要になるのは**Xcode11でiOS12.x以下をターゲットとしたプロジェクトを作成した時**だと思います。
32
+
33
+
34
+
35
+ 手元で以下のようなコードで生成したViewControllerをルートにして実行することができたので、
36
+
37
+ 参考として貼っておきます。
38
+
39
+
40
+
41
+ ```Swift
42
+
43
+ // CodeViewController
44
+
45
+ import UIKit
46
+
47
+
48
+
49
+ final class CodeViewController: UIViewController {
50
+
51
+
52
+
53
+ // MARK: - UI
54
+
55
+
56
+
57
+ lazy var titleLabel: UILabel = {
58
+
59
+ let label = UILabel()
60
+
61
+ label.translatesAutoresizingMaskIntoConstraints = false
62
+
63
+ label.font = UIFont.boldSystemFont(ofSize: 18)
64
+
65
+ label.text = "Title"
66
+
67
+ return label
68
+
69
+ }()
70
+
71
+
72
+
73
+ lazy var descLabel: UILabel = {
74
+
75
+ let label = UILabel()
76
+
77
+ label.translatesAutoresizingMaskIntoConstraints = false
78
+
79
+ label.font = UIFont.systemFont(ofSize: 15)
80
+
81
+ label.textColor = UIColor.lightGray
82
+
83
+ label.text = "Desc"
84
+
85
+ return label
86
+
87
+ }()
88
+
89
+
90
+
91
+ lazy var button: UIButton = {
92
+
93
+ let button = UIButton()
94
+
95
+ button.translatesAutoresizingMaskIntoConstraints = false
96
+
97
+ button.setTitle("Button", for: .normal)
98
+
99
+ button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 15)
100
+
101
+ button.titleLabel?.textColor = UIColor.white
102
+
103
+ button.backgroundColor = UIColor.blue
104
+
105
+ button.layer.cornerRadius = 4.0
106
+
107
+ return button
108
+
109
+ }()
110
+
111
+
112
+
113
+ // MARK: - Lifecycle
114
+
115
+
116
+
117
+ override func viewDidLoad() {
118
+
119
+ super.viewDidLoad()
120
+
121
+
122
+
123
+ // UI
124
+
125
+ view.backgroundColor = .white
126
+
127
+ view.addSubview(titleLabel)
128
+
129
+ view.addSubview(descLabel)
130
+
131
+ view.addSubview(button)
132
+
133
+ setupLayout()
134
+
135
+ }
136
+
137
+ }
138
+
139
+
140
+
141
+ // MARK: - AutoLayout
142
+
143
+ extension CodeViewController {
144
+
145
+
146
+
147
+ func setupLayout() {
148
+
149
+ // titleLabel
150
+
151
+ NSLayoutConstraint.activate([
152
+
153
+ titleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 0),
154
+
155
+ titleLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 0)
156
+
157
+ ])
158
+
159
+
160
+
161
+ // descLabel
162
+
163
+ NSLayoutConstraint.activate([
164
+
165
+ descLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8),
166
+
167
+ descLabel.centerXAnchor.constraint(equalTo: titleLabel.centerXAnchor, constant: 0)
168
+
169
+ ])
170
+
171
+
172
+
173
+ // button
174
+
175
+ NSLayoutConstraint.activate([
176
+
177
+ button.topAnchor.constraint(equalTo: descLabel.bottomAnchor, constant: 16),
178
+
179
+ button.centerXAnchor.constraint(equalTo: descLabel.centerXAnchor, constant: 0),
180
+
181
+ button.widthAnchor.constraint(equalToConstant: 88),
182
+
183
+ button.heightAnchor.constraint(equalToConstant: 44)
184
+
185
+ ])
186
+
187
+ }
188
+
189
+ }
190
+
191
+
192
+
193
+ ```
194
+
195
+
196
+
197
+ AppDelegateはプロジェクト生成時のままです。
198
+
199
+
200
+
201
+ ```Swift
202
+
203
+ // AppDelegate
204
+
205
+ import UIKit
206
+
207
+
208
+
209
+ @UIApplicationMain
210
+
211
+ class AppDelegate: UIResponder, UIApplicationDelegate {
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
220
+
221
+ // Override point for customization after application launch.
222
+
223
+ return true
224
+
225
+ }
226
+
227
+
228
+
229
+ // MARK: UISceneSession Lifecycle
230
+
231
+
232
+
233
+ func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
234
+
235
+ // Called when a new scene session is being created.
236
+
237
+ // Use this method to select a configuration to create the new scene with.
238
+
239
+ return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
240
+
241
+ }
242
+
243
+
244
+
245
+ func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
246
+
247
+ // Called when the user discards a scene session.
248
+
249
+ // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
250
+
251
+ // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
252
+
253
+ }
254
+
255
+
256
+
257
+
258
+
259
+ }
260
+
261
+ ```
262
+
263
+
264
+
265
+ SceneDelegateが`window`プロパティを持っているようなので、
266
+
267
+ ここでrootViewControllerの設定をしました。
268
+
269
+ 色々変わっていたので[こちら](https://qiita.com/rc_code/items/795ddadb98dfa09d10e6)を参考にさせていただきました。
270
+
271
+
272
+
273
+ ```Swift
274
+
275
+ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
276
+
277
+
278
+
279
+ var window: UIWindow?
280
+
281
+
282
+
283
+
284
+
285
+ func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
286
+
287
+ // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
288
+
289
+ // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
290
+
291
+ // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
292
+
293
+ guard let _ = (scene as? UIWindowScene) else { return }
294
+
295
+
296
+
297
+ if let windowScene = scene as? UIWindowScene {
298
+
299
+ let window = UIWindow(windowScene: windowScene)
300
+
301
+ window.rootViewController = CodeViewController(nibName: nil, bundle: nil)
302
+
303
+ self.window = window
304
+
305
+ window.makeKeyAndVisible()
306
+
307
+ }
308
+
309
+ }
310
+
311
+
312
+
313
+ func sceneDidDisconnect(_ scene: UIScene) {
314
+
315
+ // Called as the scene is being released by the system.
316
+
317
+ // This occurs shortly after the scene enters the background, or when its session is discarded.
318
+
319
+ // Release any resources associated with this scene that can be re-created the next time the scene connects.
320
+
321
+ // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
322
+
323
+ }
324
+
325
+
326
+
327
+ func sceneDidBecomeActive(_ scene: UIScene) {
328
+
329
+ // Called when the scene has moved from an inactive state to an active state.
330
+
331
+ // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
332
+
333
+ }
334
+
335
+
336
+
337
+ func sceneWillResignActive(_ scene: UIScene) {
338
+
339
+ // Called when the scene will move from an active state to an inactive state.
340
+
341
+ // This may occur due to temporary interruptions (ex. an incoming phone call).
342
+
343
+ }
344
+
345
+
346
+
347
+ func sceneWillEnterForeground(_ scene: UIScene) {
348
+
349
+ // Called as the scene transitions from the background to the foreground.
350
+
351
+ // Use this method to undo the changes made on entering the background.
352
+
353
+ }
354
+
355
+
356
+
357
+ func sceneDidEnterBackground(_ scene: UIScene) {
358
+
359
+ // Called as the scene transitions from the foreground to the background.
360
+
361
+ // Use this method to save data, release shared resources, and store enough scene-specific state information
362
+
363
+ // to restore the scene back to its current state.
364
+
365
+ }
366
+
367
+
368
+
369
+
370
+
371
+ }
372
+
373
+ ```
374
+
375
+
376
+
377
+ この状態で`Main`のStoryboardを削除したところ質問者様と同じ
378
+
379
+
380
+
381
+ > Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle NSBundle
382
+
383
+
384
+
385
+ 上記のエラーが出たので、
386
+
387
+ Xcodeの`Main Interface`を空にして、
388
+
389
+ info.plistの`Scene Configuration`の`Storyboard Name`の項目を削除しました。
390
+
391
+
392
+
393
+ ![info.plist](ecbc47ffd58bc39e91cd339f7a0d4aaf.png)
394
+
395
+
396
+
397
+ これで一応エラーなしで起動することができました、
398
+
399
+ 正直まだ正しい対応なのか確証が持てていないので、もう少し調査する必要があるかもしれません。
400
+
401
+ 曖昧な回答しかできず申し訳ありません。