回答編集履歴
1
データ監視の終了について追記
test
CHANGED
@@ -14,9 +14,15 @@
|
|
14
14
|
|
15
15
|
- データ更新のたびにhogearrayに全要素を追加していく処理はやめる
|
16
16
|
|
17
|
+
- データの監視を終えるときにremoveObserverWithHandleを呼ぶ
|
18
|
+
|
17
19
|
|
18
20
|
|
19
21
|
```swift
|
22
|
+
|
23
|
+
private var observer: UInt = 0
|
24
|
+
|
25
|
+
|
20
26
|
|
21
27
|
// 修正例
|
22
28
|
|
@@ -32,7 +38,7 @@
|
|
32
38
|
|
33
39
|
let defaultPlace = DBRef.child("table/orderorder")
|
34
40
|
|
35
|
-
defaultPlace.observe(.value, with: { snapshot in
|
41
|
+
self.observer = defaultPlace.observe(.value, with: { snapshot in
|
36
42
|
|
37
43
|
var array: [String] = []
|
38
44
|
|
@@ -66,4 +72,16 @@
|
|
66
72
|
|
67
73
|
}
|
68
74
|
|
75
|
+
|
76
|
+
|
77
|
+
// データ監視の終了の例(タイミングは適当です)
|
78
|
+
|
79
|
+
override func viewDidUnload() {
|
80
|
+
|
81
|
+
super.viewDidUnload();
|
82
|
+
|
83
|
+
DBRef.child("table/orderorder").removeObserver(withHandle: self.observer)
|
84
|
+
|
85
|
+
}
|
86
|
+
|
69
87
|
```
|