質問編集履歴

6

解決方法を自己解決の欄に書き込み

2016/11/02 03:03

投稿

Kochan
Kochan

スコア56

test CHANGED
File without changes
test CHANGED
@@ -282,184 +282,6 @@
282
282
 
283
283
 
284
284
 
285
- ###解決方法
286
-
287
-
288
-
289
- fromageblancさんに教えていただいた下記のリンクよりbreakpointを設定したことで、原因がFIRDatabaseにあることが分かりました。
290
-
291
- http://qiita.com/mono0926/items/bf70c7ef15db046ee163
292
-
293
-
294
-
295
- 次に、fuzzballさんより教えていただいたprint("文字列")を挟むデバッグ方法でどこまでコードが通っているのかを特定することができました。
296
-
297
-
298
-
299
- ``print("A")
300
-
301
- let ref = FIRDatabase.database().reference()
302
-
303
- print("B")
304
-
305
- ref.child("messages").childByAutoId().setValue(
306
-
307
- ["senderId": senderId, "text": text, "displayName": senderDisplayName])
308
-
309
- print("C")
310
-
311
- ``
312
-
313
-
314
-
315
- まずはAまで通っていました。
316
-
317
- これをBまで通すために
318
-
319
- AppDelegate.swiftをswift3に対応させ書き換え、FIRApp.configure()を追加しました。
320
-
321
-
322
-
323
- ``func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
324
-
325
- FIRApp.configure()
326
-
327
- //FIRApp.configure()を追加
328
-
329
- return true
330
-
331
- }``
332
-
333
-
334
-
335
- その後、Cまで通すため
336
-
337
-
338
-
339
- ``setValue(
340
-
341
- ["senderId": senderId, "text": text, "displayName": senderDisplayName])
342
-
343
- ``
344
-
345
- に as [AnyHashable:Any]を追加し、
346
-
347
-
348
-
349
- ``setValue(
350
-
351
- ["senderId": senderId, "text": text, "displayName": senderDisplayName]as [AnyHashable:Any])
352
-
353
- ``
354
-
355
-
356
-
357
- としました。
358
-
359
- Firebase側ではNS系のものしか格納出来ないので
360
-
361
- ここでNSObjectとして指定する必要がありました。
362
-
363
-
364
-
365
- swift2では [NSObject: AnyObject]
366
-
367
- と書いていたものが
368
-
369
- swift3では [AnyHashable: Any]
370
-
371
- となっています。
372
-
373
-
374
-
375
- 以下ページ参照。
376
-
377
- http://qiita.com/NemotoTaka/items/565b899dafed4b803a3d
378
-
379
-
380
-
381
- ここまで追加することにより、
382
-
383
- 無事Firebaseへのデータ書き込みが完了いたしました。
384
-
385
-
386
-
387
-
388
-
389
- ご教授いただいたfuzzballさま、fromageblancさま、
390
-
391
- 本当にありがとうございました。
392
-
393
-
394
-
395
-
396
-
397
- ソースコードの修正部分を下に置いておきます。
398
-
399
-
400
-
401
-
402
-
403
- ###AppDelegate.swiftの修正部分
404
-
405
- ```
406
-
407
-
408
-
409
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
410
-
411
- FIRApp.configure()
412
-
413
- //FIRApp.configure()を追加
414
-
415
- return true
416
-
417
- }
418
-
419
- //上記部分をswift3に対応して修正 2016/11/02 1:03
420
-
421
-
422
-
423
- ```
424
-
425
-
426
-
427
- ###ViewControllerSwiftの修正部分
428
-
429
- ```
430
-
431
- override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!) {
432
-
433
- print("beforeA",text, senderId, senderDisplayName, date)
434
-
435
- inputToolbar.contentView.textView.text = ""
436
-
437
- print("A")
438
-
439
- let ref = FIRDatabase.database().reference()
440
-
441
- print("B")
442
-
443
- ref.child("messages").childByAutoId().setValue(
444
-
445
- ["senderId": senderId, "text": text, "displayName": senderDisplayName]as [AnyHashable:Any])
446
-
447
- //print文を挟み、どこまでコードが動いているかをコンソールの方へ出力。
448
-
449
- //as [AnyHashable:Any]を最後に追加 2016/11/02 1:03
450
-
451
- print("C")
452
-
453
- }
454
-
455
- ```
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
285
  ###補足情報(言語/FW/ツール等のバージョンなど)
464
286
 
465
287
  Swift3 Xcode8 iOS10

5

解説の修正

2016/11/02 03:03

投稿

Kochan
Kochan

スコア56

test CHANGED
File without changes
test CHANGED
@@ -356,9 +356,21 @@
356
356
 
357
357
  としました。
358
358
 
359
+ Firebase側ではNS系のものしか格納出来ないので
360
+
361
+ ここでNSObjectとして指定する必要がありました。
362
+
363
+
364
+
359
- これはswift2からswift3への変更で起こったエラーでした。
365
+ swift2では [NSObject: AnyObject]
366
+
360
-
367
+ と書いていたものが
368
+
361
- ![イメージ説明](955c31f39741bfcac92542d92e51a642.png)
369
+ swift3では [AnyHashable: Any]
370
+
371
+ となっています。
372
+
373
+
362
374
 
363
375
  以下ページ参照。
364
376
 

4

いただいた解決方法を記述しました。

2016/11/01 16:17

投稿

Kochan
Kochan

スコア56

test CHANGED
@@ -1 +1 @@
1
- 特に部品使っていないのに、Thread 1: signal SIGABRTのエラーが出る。
1
+ Swift3でチャットアプリ作りFirebaseにデータを書き込む際のエラーの解決方法
test CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  上記のページを参考にしてswift3とFirebaseを使ってリアルタイムチャットアプリを作ろうとしています。
6
6
 
7
+ ViewContollor.swiftをswift3に対応させようと書き換えたのですが、
8
+
9
+ Firebaseのデータベースへ書き込みができないのでそれを解決したいと思い質問させていただきました。
10
+
7
11
 
8
12
 
9
13
  cocoapodsを使ってFirebaseとJSQMessageViewControllerを導入し、
@@ -18,8 +22,6 @@
18
22
 
19
23
  みてみたのですが、ストーリーボードには何もありませんでした。
20
24
 
21
- ![イメージ説明](532bbbc0f79aa878c255f2406b0dd0c5.png)
22
-
23
25
 
24
26
 
25
27
  どうか、ご助力をお願いいたします。
@@ -28,6 +30,12 @@
28
30
 
29
31
 
30
32
 
33
+
34
+
35
+ PS:ご教授いただいた解決方法を質問の一番下に書いてあります。2016 11/2
36
+
37
+
38
+
31
39
  ###発生している問題・エラーメッセージ
32
40
 
33
41
 
@@ -84,47 +92,31 @@
84
92
 
85
93
  func applicationWillResignActive(_ application: UIApplication) {
86
94
 
87
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
88
-
89
- // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
90
-
91
95
  }
92
96
 
93
97
 
94
98
 
95
99
  func applicationDidEnterBackground(_ application: UIApplication) {
96
100
 
97
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
98
-
99
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
100
-
101
101
  }
102
102
 
103
103
 
104
104
 
105
105
  func applicationWillEnterForeground(_ application: UIApplication) {
106
106
 
107
- // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
108
-
109
107
  }
110
108
 
111
109
 
112
110
 
113
111
  func applicationDidBecomeActive(_ application: UIApplication) {
114
112
 
115
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
116
-
117
113
  }
118
114
 
119
115
 
120
116
 
121
117
  func applicationWillTerminate(_ application: UIApplication) {
122
118
 
123
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
124
-
125
- }
119
+ }
126
-
127
-
128
120
 
129
121
 
130
122
 
@@ -136,7 +128,7 @@
136
128
 
137
129
  ViewControllerSwift
138
130
 
139
- ```ここに言語を入力
131
+ ```Swift3.0
140
132
 
141
133
  import UIKit
142
134
 
@@ -206,11 +198,7 @@
206
198
 
207
199
  }
208
200
 
209
-
210
-
211
-
212
-
213
-
201
+
214
202
 
215
203
  //cellForItemAtIndexPathのIndexPathを削除、whiteColor()、grayColor()のColor()を削除。
216
204
 
@@ -292,123 +280,133 @@
292
280
 
293
281
 
294
282
 
283
+
284
+
295
- ###試したこと
285
+ ###解決方法
296
-
297
- エラーについてgoogleで検索し、
286
+
298
-
299
- ストーリーボードの接続の確認
287
+
300
-
288
+
301
- アップ後のビルドダメでした。
289
+ fromageblancさんに教えていただいた下記のリンクよりbreakpoint設定たこと、原因がFIRDatabaseにあることが分かりました。
302
-
303
-
304
290
 
305
291
  http://qiita.com/mono0926/items/bf70c7ef15db046ee163
306
292
 
293
+
294
+
295
+ 次に、fuzzballさんより教えていただいたprint("文字列")を挟むデバッグ方法でどこまでコードが通っているのかを特定することができました。
296
+
297
+
298
+
299
+ ``print("A")
300
+
307
- こちらのページを参照した結果、以下のFIRDatabaseの部分でクラッシュしているようです。
301
+ let ref = FIRDatabase.database().reference()
302
+
308
-
303
+ print("B")
309
-
310
-
304
+
311
- ![イメージ説明](e83f5c980d9540748256f0b71edddf04.png)
305
+ ref.child("messages").childByAutoId().setValue(
306
+
312
-
307
+ ["senderId": senderId, "text": text, "displayName": senderDisplayName])
313
-
314
-
308
+
315
- ###修正後のAppDelegate.swift
309
+ print("C")
316
-
310
+
317
- ```
311
+ ``
318
-
319
- import UIKit
312
+
320
-
313
+
314
+
321
- import Firebase
315
+ まずはAまで通っていました。
322
-
323
-
324
-
316
+
325
- @UIApplicationMain
317
+ これをBまで通すために
326
-
318
+
327
- class AppDelegate: UIResponder, UIApplicationDelegate {
319
+ AppDelegate.swiftをswift3に対応させ書き換え、FIRApp.configure()を追加しました。
328
-
329
-
330
-
320
+
321
+
322
+
331
- var window: UIWindow?
323
+ ``func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
- override init() {
340
-
341
- super.init()
342
324
 
343
325
  FIRApp.configure()
344
326
 
345
- }
346
-
347
- //ここの部分を追加しました。 2016/11/01 2:07
348
-
349
-
350
-
351
- private func application(application: UIApplication,
352
-
353
- didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
354
-
355
- -> Bool {
356
-
357
- //FIRApp.configure()
358
-
359
- //ここのFIRAppをコメントで無効化しました。
360
-
361
- return true
362
-
363
- }
364
-
365
-
366
-
367
-
368
-
369
- func applicationWillResignActive(_ application: UIApplication) {
370
-
371
-
372
-
373
- }
374
-
375
-
376
-
377
- func applicationDidEnterBackground(_ application: UIApplication) {
378
-
379
-
380
-
381
- }
382
-
383
-
384
-
385
- func applicationWillEnterForeground(_ application: UIApplication) {
386
-
387
-
388
-
389
- }
390
-
391
-
392
-
393
- func applicationDidBecomeActive(_ application: UIApplication) {
394
-
395
-
396
-
397
- }
398
-
399
-
400
-
401
- func applicationWillTerminate(_ application: UIApplication) {
402
-
403
-
404
-
405
- }
406
-
407
-
408
-
409
-
410
-
411
- }
327
+ //FIRApp.configure()を追加
328
+
329
+ return true
330
+
331
+ }``
332
+
333
+
334
+
335
+ その後、Cまで通すため
336
+
337
+
338
+
339
+ ``setValue(
340
+
341
+ ["senderId": senderId, "text": text, "displayName": senderDisplayName])
342
+
343
+ ``
344
+
345
+ as [AnyHashable:Any]を追加し、
346
+
347
+
348
+
349
+ ``setValue(
350
+
351
+ ["senderId": senderId, "text": text, "displayName": senderDisplayName]as [AnyHashable:Any])
352
+
353
+ ``
354
+
355
+
356
+
357
+ としました。
358
+
359
+ これはswift2からswift3への変更で起こったエラーでした。
360
+
361
+ ![イメージ説明](955c31f39741bfcac92542d92e51a642.png)
362
+
363
+ 以下ページ参照。
364
+
365
+ http://qiita.com/NemotoTaka/items/565b899dafed4b803a3d
366
+
367
+
368
+
369
+ ここまで追加することにより、
370
+
371
+ 無事Firebaseへのデータ書き込みが完了いたしました。
372
+
373
+
374
+
375
+
376
+
377
+ ご教授いただいたfuzzballさま、fromageblancさま、
378
+
379
+ 本当にありがとうございました。
380
+
381
+
382
+
383
+
384
+
385
+ ソースコードの修正部分を下に置いておきます。
386
+
387
+
388
+
389
+
390
+
391
+ ###AppDelegate.swiftの修正部分
392
+
393
+ ```
394
+
395
+
396
+
397
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
398
+
399
+ FIRApp.configure()
400
+
401
+ //FIRApp.configure()を追加
402
+
403
+ return true
404
+
405
+ }
406
+
407
+ //上記部分をswift3に対応して修正 2016/11/02 1:03
408
+
409
+
412
410
 
413
411
  ```
414
412
 
@@ -418,7 +416,7 @@
418
416
 
419
417
  ```
420
418
 
421
- override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!) {
419
+ override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!) {
422
420
 
423
421
  print("beforeA",text, senderId, senderDisplayName, date)
424
422
 
@@ -430,23 +428,13 @@
430
428
 
431
429
  print("B")
432
430
 
433
-
434
-
435
- func toAnyObject() -> [AnyHashable:Any] {
436
-
437
- return ["senderId": senderId, "text": text, "displayName": senderDisplayName] as [AnyHashable:Any]
438
-
439
- }
440
-
441
- //この上の部分を追加
442
-
443
-
444
-
445
431
  ref.child("messages").childByAutoId().setValue(
446
432
 
447
433
  ["senderId": senderId, "text": text, "displayName": senderDisplayName]as [AnyHashable:Any])
448
434
 
435
+ //print文を挟み、どこまでコードが動いているかをコンソールの方へ出力。
436
+
449
- //as [AnyHashable:Any]を最後に追加
437
+ //as [AnyHashable:Any]を最後に追加 2016/11/02 1:03
450
438
 
451
439
  print("C")
452
440
 

3

修正部分の追加。

2016/11/01 16:11

投稿

Kochan
Kochan

スコア56

test CHANGED
File without changes
test CHANGED
@@ -414,6 +414,52 @@
414
414
 
415
415
 
416
416
 
417
+ ###ViewControllerSwiftの修正部分
418
+
419
+ ```
420
+
421
+ override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!) {
422
+
423
+ print("beforeA",text, senderId, senderDisplayName, date)
424
+
425
+ inputToolbar.contentView.textView.text = ""
426
+
427
+ print("A")
428
+
429
+ let ref = FIRDatabase.database().reference()
430
+
431
+ print("B")
432
+
433
+
434
+
435
+ func toAnyObject() -> [AnyHashable:Any] {
436
+
437
+ return ["senderId": senderId, "text": text, "displayName": senderDisplayName] as [AnyHashable:Any]
438
+
439
+ }
440
+
441
+ //この上の部分を追加
442
+
443
+
444
+
445
+ ref.child("messages").childByAutoId().setValue(
446
+
447
+ ["senderId": senderId, "text": text, "displayName": senderDisplayName]as [AnyHashable:Any])
448
+
449
+ //as [AnyHashable:Any]を最後に追加
450
+
451
+ print("C")
452
+
453
+ }
454
+
455
+ ```
456
+
457
+
458
+
459
+
460
+
461
+
462
+
417
463
  ###補足情報(言語/FW/ツール等のバージョンなど)
418
464
 
419
465
  Swift3 Xcode8 iOS10

2

ソース文の変更点の追加

2016/11/01 06:44

投稿

Kochan
Kochan

スコア56

test CHANGED
File without changes
test CHANGED
@@ -312,6 +312,108 @@
312
312
 
313
313
 
314
314
 
315
+ ###修正後のAppDelegate.swift
316
+
317
+ ```
318
+
319
+ import UIKit
320
+
321
+ import Firebase
322
+
323
+
324
+
325
+ @UIApplicationMain
326
+
327
+ class AppDelegate: UIResponder, UIApplicationDelegate {
328
+
329
+
330
+
331
+ var window: UIWindow?
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+ override init() {
340
+
341
+ super.init()
342
+
343
+ FIRApp.configure()
344
+
345
+ }
346
+
347
+ //ここの部分を追加しました。 2016/11/01 2:07
348
+
349
+
350
+
351
+ private func application(application: UIApplication,
352
+
353
+ didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
354
+
355
+ -> Bool {
356
+
357
+ //FIRApp.configure()
358
+
359
+ //ここのFIRAppをコメントで無効化しました。
360
+
361
+ return true
362
+
363
+ }
364
+
365
+
366
+
367
+
368
+
369
+ func applicationWillResignActive(_ application: UIApplication) {
370
+
371
+
372
+
373
+ }
374
+
375
+
376
+
377
+ func applicationDidEnterBackground(_ application: UIApplication) {
378
+
379
+
380
+
381
+ }
382
+
383
+
384
+
385
+ func applicationWillEnterForeground(_ application: UIApplication) {
386
+
387
+
388
+
389
+ }
390
+
391
+
392
+
393
+ func applicationDidBecomeActive(_ application: UIApplication) {
394
+
395
+
396
+
397
+ }
398
+
399
+
400
+
401
+ func applicationWillTerminate(_ application: UIApplication) {
402
+
403
+
404
+
405
+ }
406
+
407
+
408
+
409
+
410
+
411
+ }
412
+
413
+ ```
414
+
415
+
416
+
315
417
  ###補足情報(言語/FW/ツール等のバージョンなど)
316
418
 
317
419
  Swift3 Xcode8 iOS10

1

試したことの追加

2016/10/31 17:08

投稿

Kochan
Kochan

スコア56

test CHANGED
File without changes
test CHANGED
@@ -302,6 +302,16 @@
302
302
 
303
303
 
304
304
 
305
+ http://qiita.com/mono0926/items/bf70c7ef15db046ee163
306
+
307
+ こちらのページを参照した結果、以下のFIRDatabaseの部分でクラッシュしているようです。
308
+
309
+
310
+
311
+ ![イメージ説明](e83f5c980d9540748256f0b71edddf04.png)
312
+
313
+
314
+
305
315
  ###補足情報(言語/FW/ツール等のバージョンなど)
306
316
 
307
317
  Swift3 Xcode8 iOS10