回答編集履歴
5
処理を一部修正しました。
test
CHANGED
@@ -146,9 +146,17 @@
|
|
146
146
|
|
147
147
|
let user = User(dictionary: dict)
|
148
148
|
|
149
|
-
|
149
|
+
|
150
150
|
|
151
|
+
// メインスレッドで処理をする
|
152
|
+
|
153
|
+
DispatchQueue.main.async { [weak self] in
|
154
|
+
|
155
|
+
self?.nameTextField.text = user.name
|
156
|
+
|
151
|
-
iconImageView.image = user.icon
|
157
|
+
self?.iconImageView.image = user.icon
|
158
|
+
|
159
|
+
}
|
152
160
|
|
153
161
|
}
|
154
162
|
|
4
一部修正しました。
test
CHANGED
@@ -86,27 +86,21 @@
|
|
86
86
|
|
87
87
|
let urlString = dictionary["userIcon"] as! String
|
88
88
|
|
89
|
+
let decodedData = Data(base64Encoded: urlString, options: Data.Base64DecodingOptions.ignoreUnknownCharacters)
|
90
|
+
|
91
|
+
let decodedIcon = UIImage(data: decodedData!)
|
92
|
+
|
93
|
+
self.icon = decodedIcon!
|
89
94
|
|
90
95
|
|
91
|
-
// ごめんなさい間違えてました
|
92
|
-
|
93
|
-
let url = URL(string: urlString)!
|
94
|
-
|
95
|
-
let data = try Data(contentsOf: url)
|
96
|
-
|
97
|
-
let image = UIImage(data: data)!
|
98
|
-
|
99
|
-
self.icon = image
|
100
96
|
|
101
97
|
} catch {
|
102
98
|
|
99
|
+
// 何かしらのエラー処理をするまたは
|
100
|
+
|
103
101
|
// ※ダミーの画像などで初期化が必要
|
104
102
|
|
105
|
-
self.icon = UIImage()
|
103
|
+
self.icon = UIImage()
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
// 何かしらのエラー処理
|
110
104
|
|
111
105
|
}
|
112
106
|
|
3
一部修正しました。
test
CHANGED
@@ -92,7 +92,7 @@
|
|
92
92
|
|
93
93
|
let url = URL(string: urlString)!
|
94
94
|
|
95
|
-
let data = try Data(contentsOf: url
|
95
|
+
let data = try Data(contentsOf: url)
|
96
96
|
|
97
97
|
let image = UIImage(data: data)!
|
98
98
|
|
2
一部修正しました。
test
CHANGED
@@ -84,7 +84,13 @@
|
|
84
84
|
|
85
85
|
do {
|
86
86
|
|
87
|
-
let url = dictionary["userIcon"] as! String
|
87
|
+
let urlString = dictionary["userIcon"] as! String
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
// ごめんなさい間違えてました
|
92
|
+
|
93
|
+
let url = URL(string: urlString)!
|
88
94
|
|
89
95
|
let data = try Data(contentsOf: url!)
|
90
96
|
|
1
一部修正と追記を行いました。
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
-
myProfileLabel.text = user["user
|
17
|
+
myProfileLabel.text = user["userName"] as? String
|
18
18
|
|
19
19
|
```
|
20
20
|
|
@@ -24,9 +24,9 @@
|
|
24
24
|
|
25
25
|
```
|
26
26
|
|
27
|
-
// ↓本当はuser
|
27
|
+
// ↓本当はuserName
|
28
28
|
|
29
|
-
myProfileLabel.text = user["user
|
29
|
+
myProfileLabel.text = user["userNema"] as? String
|
30
30
|
|
31
31
|
|
32
32
|
|
@@ -76,11 +76,15 @@
|
|
76
76
|
|
77
77
|
init(dictionary: [String: Any]) {
|
78
78
|
|
79
|
-
self.username = dictionary["user
|
79
|
+
self.username = dictionary["userName"] as! String
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
// dictionaryに対するエラーチェックは省略しています
|
80
84
|
|
81
85
|
do {
|
82
86
|
|
83
|
-
let url = dictionary["
|
87
|
+
let url = dictionary["userIcon"] as! String
|
84
88
|
|
85
89
|
let data = try Data(contentsOf: url!)
|
86
90
|
|
@@ -89,6 +93,12 @@
|
|
89
93
|
self.icon = image
|
90
94
|
|
91
95
|
} catch {
|
96
|
+
|
97
|
+
// ※ダミーの画像などで初期化が必要
|
98
|
+
|
99
|
+
self.icon = UIImage()]
|
100
|
+
|
101
|
+
|
92
102
|
|
93
103
|
// 何かしらのエラー処理
|
94
104
|
|
@@ -103,3 +113,45 @@
|
|
103
113
|
|
104
114
|
|
105
115
|
一意見ですので、ぜひ他の方のご意見も参考してみてください。
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
【追記】
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
Userインスタンスを作成するのは下記のような形でできませんでしょうか?
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
ref.queryLimited(toLast: 1).observe(DataEventType.value, with: { (snapshot) in
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
for item in snapshot.children {
|
136
|
+
|
137
|
+
let snap = item as! DataSnapshot
|
138
|
+
|
139
|
+
let dict = snap.value as! [String: Any]
|
140
|
+
|
141
|
+
// データの中身を確認
|
142
|
+
|
143
|
+
print(dict)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
let user = User(dictionary: dict)
|
148
|
+
|
149
|
+
nameTextField.text = user.name
|
150
|
+
|
151
|
+
iconImageView.image = user.icon
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
})
|
156
|
+
|
157
|
+
```
|