2
我正在使用解析實現模型。在製作模型期間「從初始化程序返回而未初始化所有存儲的屬性」錯誤
這是我的代碼。
import Foundation
import UIKit
import Parse
class User {
var objectId : String
var username : String
var nickName : String
var phoneNumber : String
var preferPhoneNumber : String
var emailAddress : String
var preferemailAddress : String
var emailVerified : Bool
var createdAt : NSDate
var updatedAt : NSDate
var profile_picture : UIImage
init(objectId:String, username:String, nickName:String, phoneNumber: String, preferPhoneNumber : String, emailAddress : String, preferemailAddress : String, emailVerified : Bool){
self.objectId = (PFUser.currentUser()?.objectId)!
self.username = (PFUser.currentUser()?.username)!
if var nickName = (PFUser.currentUser()?.objectForKey("nickName") as? String){
(PFUser.currentUser()?.objectForKey("nickName") as? String)
}else{
"!NoData"
}
if var phoneNumber = (PFUser.currentUser()?.objectForKey("phoneNumber") as? String){
self.phoneNumber = (PFUser.currentUser()?.objectForKey("phoneNumber") as? String)!
}else{
"!NoData"
}
if var preferPhoneNumber = (PFUser.currentUser()?.objectForKey("preferPhoneNumber") as? String){
self.preferPhoneNumber = (PFUser.currentUser()?.objectForKey("preferPhoneNumber") as? String)!
}else{
"!NoData"
}
if var emailAddress = (PFUser.currentUser()?.objectForKey("emailAddress") as? String){
self.emailAddress = (PFUser.currentUser()?.objectForKey("emailAddress") as? String)!
}else{
"!NoData"
}
if var preferemailAddress = (PFUser.currentUser()?.objectForKey("preferemailAddress") as? String){
self.preferemailAddress = (PFUser.currentUser()?.objectForKey("preferemailAddress") as? String)!
}else{
"!NoData"
}
if var emailVerified = (PFUser.currentUser()?.objectForKey("emailVerified") as? Bool){
self.emailVerified = (PFUser.currentUser()?.objectForKey("emailVerified") as? Bool)!
}else{
"!NoData"
}
}
}
在我的代碼,我得到一個錯誤,「從初始返回而不初始化所有存儲屬性」決策模型中。
我試着把「return nil」放在最後,這不是解決方案。
所以我想知道如何初始化存儲的屬性?
或如何解決此錯誤?
我刪除了這三個值,還是我收到同樣的錯誤。 –
@JanghyupLee請閱讀我的完整答案,您必須更改所有存儲的屬性類型,或者在每種情況下爲它們分配一個值 – luk2302