私はこのトピックが以前に議論されたことは知っていますが、私のコードで働くStackOverflowの解決策は見つかりませんでした。 Swift 3で動作するようにコードを更新するにはどうすればよいですか?タイプ 'Any'にはFirebaseの添え字メンバーがありません
import Foundation
import Firebase
import FirebaseDatabase
import FirebaseStorage
struct Comment {
var image: String!
var postID: String!
var description: String!
var username: String!
var price: String!
var rating: String!
var title: String!
var ref: FIRDatabaseReference?
var key: String!
init(postID: String, image: String, description: String, username: String, title: String, rating: String, price: String, key: String = ""){
self.description = description
self.postID = postID
self.username = username
self.title = title
self.rating = rating
self.price = price
self.image = image
self.ref = FIRDatabase.database().reference()
}
init(snapshot: FIRDataSnapshot){
self.description = snapshot.value!["description"] as! String // error here
self.postID = snapshot.value!["postID"] as! String // error here
self.title = snapshot.value!["title"] as! String // error here
self.rating = snapshot.value!["rating"] as! String // error here
self.price = snapshot.value!["price"] as! String // error here
self.image = snapshot.value!["image"] as! String // error here
self.key = snapshot.key
self.ref = snapshot.ref
}
func toAnyObject() -> [String: AnyObject] {
return ["image": image, "description": description , "username": username, "postId": postID, "title": title, "rating": rating, "price": price]
}
}
を使用します。 'let keyValue = snapshot.value as!辞書 'であり、' snapshot.value'は 'Any'として宣言されています。 –
@gabe Any型Swift辞書型[String:AnyObject]にキャストする必要があります。あなたのスナップショットは辞書の配列です。 –
@ Sachin-Vasありがとう。しかし、私はエラー 'タイプ'の値を割り当てることができません '辞書'を入力する '文字列!' ' –
gabe