0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Swift】Firebase利用時にThe data couldn’t be read because it is missing.が発生する。

Posted at

Firebase利用時にThe data could't be read because it is missing

エラーの意味:
データが欠落しているため、データを読み取ることができませんでした。

対処法:
コードで定義したModelの項目数、項目名と、Firebaseに登録する項目数、項目名が正しいかどうかを確認する。

エラーになる例

Model
/** 項目数は11個*/
struct User : Identifiable,Decodable {
    @DocumentID var id : String?
    var username : String
    var fullname : String
    var profileImageUrl : String
    var email : String
    var job : String
    var birth : String
    var gender : String
    var purpose : String
    var price : String
    var url : String
}
Firebaseに登録する内容
/* 項目数は10個
 * Modelの項目数と差分が出ている状態
 */
let data = ["uid" : user.uid, "username" : username.lowercased() ,
 "fullname" : fullname , "profileImageUrl" : profileImageUrl , 
 "email": email, "job" : job , "birth" : birth , "gender" : gender , 
 "purpose" : purpose , "price" : price]
}

エラーにならない例

Model
/** 項目数は11個*/
struct User : Identifiable,Decodable {
    @DocumentID var id : String?
    var username : String
    var fullname : String
    var profileImageUrl : String
    var email : String
    var job : String
    var birth : String
    var gender : String
    var purpose : String
    var price : String
    var url : String
}
Firebaseに登録する内容
/* 項目数は11個
 * Modelの項目数と差分が出ていない状態
 */
let data = ["uid" : user.uid, "username" : username.lowercased() ,
 "fullname" : fullname , "profileImageUrl" : profileImageUrl , 
 "email": email, "job" : job , "birth" : birth , "gender" : gender , 
 "purpose" : purpose , "price" : price , "url" : url]
}

まとめ

Firebaseに登録するカラムを追加した時は、Modelの修正も忘れないようにしましょう✊

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?