アレイの場合、それは本当に簡単です。 firebaseの変更を聴く関数があれば、キーの情報がlet apple
のように格納されていると思います。次に、noOfFruitの値を次のようになります。
let apple = // what you had before
guard let noOfFruit = apple["noOfFruit"] as? [Int] else {
return
}
//Here you have the array of ints called noOfFruit
画像の場合、いくつかのオプションがあります。最初の(と悪いものは)synchrounsly URLのデータを取得し、次のような画像表示に設定することです。このアプローチで
let url = URL(string: picture)
let data = try? Data(contentsOf: url!) //this may break due to force unwrapping, make sure it exists
imageView.image = UIImage(data: data!)
の事、それは、NOT OKだということです。メインスレッドがリクエストを作成してイメージをダウンロードしている間、アプリケーションは応答しなくなります。
より良いアプローチはasynchronously.ThereなAlamofireImageとして本当に役立ついくつかのライブラリは、ですが、それは本当に簡単ベアボーン財団で行うことができ、それをフェッチ行くことであろう。これを行うには、次のようURLSessionクラスを使用する必要があります。
guard let url = URL(string: picture) else {
return
}
URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
print(error)
return
}
//Remember to do UI updates in the main thread
DispatchQueue.main.async {
self.myImageView.image = UIImage(data: data!)
}
}.resume()
JSONを読むために非常に簡単です: '{}は' '[]'配列、二重引用符内のテキストは 'STRING' diictionaryを表し、ドットを含む数字は 'Double'、ドットは' Int'、 'true'または' false'は 'Bool'で、' 012Nの 'NSNull'は' 'です。何百もの関連する質問がStackoverflowでJSONを解析する方法があります。 –
vadian