我有一个 "firebase user" 的 swift 文件,名为 Fuser.swift,其中有一个 class,名为 FUser 包含我想保存在 firebase 中的所有信息
I have a swift file for "firebase user" called Fuser.swift which has a class called FUser Contains all info I want to save in firebase
这是 FUser 中出现问题的代码:
Cannot invoke initializer for type 'FUser' with an argument list of type '(_objectId: String, _pushId: String, _createdAt: Date, _updatedAt: Date, _firstname: String, _lastname: String)'
class func registerUserWith(email: String, password: String, firstName: String, lastName: String, completion: @escaping (_ error: Error?) -> Void ) {
Auth.auth().createUser(withEmail: email, password: password) {
(firuser, error) in
if error != nil {
completion(error)
return
}
let fUser = FUser(_objectId: firuser!.user.uid, _pushId: "", _createdAt: Date(), _updatedAt: Date(), _firstname: firstName, _lastname: lastName)
saveUserLocally(fUser: fUser)
saveUserInBackground(fUser: fUser)
completion(error)
}
}
& 如果您想查看某些内容,这是文件:
导入基金会
导入 Firebase
导入 FirebaseFirestore
导入 FirebaseAuth
class FUser {
let objectId : String
var pushId : String?
let createdAt : Date
var updatedAt : Date
var coins : Int
var company : String
var firstName : String
var lastName : String
var fullName : String
var avatar : String
var phoneNumber : String
var additionalPhoneNumber : String
var isAgent : Bool
var favouriteProperities : [String]
init(_objectId : String ,_pushId : String?,_createdAt : Date,_updatedAt : Date,_coins : Int,_firstName: String,_lastName:String,_fullName:String,_avatar:String,_phoneNumber:String) {
objectId = _objectId
pushId = _pushId
createdAt = _createdAt
updatedAt = _updatedAt
coins = _coins
company = ""
firstName = _firstName
lastName = _lastName
fullName = _firstName + " " + _lastName
avatar = _avatar
phoneNumber = _phoneNumber
additionalPhoneNumber = ""
isAgent = false
favouriteProperities = []
}
init(_dictionary : NSDictionary) {
///...
}
问题出在您的 init 中,您将 _ 附加到它旁边的单词。
改成
init(_ objectId : String ,_ pushId : String?,_ createdAt : Date,_ updatedAt : Date,_ coins : Int, _firstName: String,_ lastName:String,_ fullName:String,_ avatar:String,_ phoneNumber:String)
您正在尝试使用不存在的初始化方法。
您致电:
init(_objectId: firuser!.user.uid,
_pushId: "",
_createdAt: Date(),
_updatedAt: Date(),
_firstname: firstName,
_lastname: lastName)
但是你声明的初始化方法是:
init(_objectId : String ,
_pushId : String?,
_createdAt : Date,
_updatedAt : Date,
_coins : Int,
_firstName: String,
_lastName:String,
_fullName:String,
_avatar:String,
_phoneNumber:String)
不是一回事。您可以在调用中包含额外元素或在签名中提供默认值。
例如
init(_objectId : String ,
_pushId : String?,
_createdAt : Date,
_updatedAt : Date,
_coins : Int = 0,
_firstName: String,
_lastName:String,
_fullName:String = "",
_avatar:String = "",
_phoneNumber:String = "")
还要确保拼写正确,因为所谓的 _firstname
与签名 _firstName
不同。
也是风格点。 _
字符在方法签名中是特殊的,因此虽然 _firstName
是一个合法的签名,但对于任何未来的 reader 来说都会让人感到困惑。您是否打算使用 _ firstName: String
来使参数名称不是必需的?或者只是 firstName: String
这将是一种正常的风格。
这是 FUser 中出现问题的代码:
Cannot invoke initializer for type 'FUser' with an argument list of type '(_objectId: String, _pushId: String, _createdAt: Date, _updatedAt: Date, _firstname: String, _lastname: String)'
class func registerUserWith(email: String, password: String, firstName: String, lastName: String, completion: @escaping (_ error: Error?) -> Void ) {
Auth.auth().createUser(withEmail: email, password: password) {
(firuser, error) in
if error != nil {
completion(error)
return
}
let fUser = FUser(_objectId: firuser!.user.uid, _pushId: "", _createdAt: Date(), _updatedAt: Date(), _firstname: firstName, _lastname: lastName)
saveUserLocally(fUser: fUser)
saveUserInBackground(fUser: fUser)
completion(error)
}
}
& 如果您想查看某些内容,这是文件:
导入基金会 导入 Firebase 导入 FirebaseFirestore 导入 FirebaseAuth
class FUser {
let objectId : String
var pushId : String?
let createdAt : Date
var updatedAt : Date
var coins : Int
var company : String
var firstName : String
var lastName : String
var fullName : String
var avatar : String
var phoneNumber : String
var additionalPhoneNumber : String
var isAgent : Bool
var favouriteProperities : [String]
init(_objectId : String ,_pushId : String?,_createdAt : Date,_updatedAt : Date,_coins : Int,_firstName: String,_lastName:String,_fullName:String,_avatar:String,_phoneNumber:String) {
objectId = _objectId
pushId = _pushId
createdAt = _createdAt
updatedAt = _updatedAt
coins = _coins
company = ""
firstName = _firstName
lastName = _lastName
fullName = _firstName + " " + _lastName
avatar = _avatar
phoneNumber = _phoneNumber
additionalPhoneNumber = ""
isAgent = false
favouriteProperities = []
}
init(_dictionary : NSDictionary) {
///...
}
问题出在您的 init 中,您将 _ 附加到它旁边的单词。 改成
init(_ objectId : String ,_ pushId : String?,_ createdAt : Date,_ updatedAt : Date,_ coins : Int, _firstName: String,_ lastName:String,_ fullName:String,_ avatar:String,_ phoneNumber:String)
您正在尝试使用不存在的初始化方法。
您致电:
init(_objectId: firuser!.user.uid,
_pushId: "",
_createdAt: Date(),
_updatedAt: Date(),
_firstname: firstName,
_lastname: lastName)
但是你声明的初始化方法是:
init(_objectId : String ,
_pushId : String?,
_createdAt : Date,
_updatedAt : Date,
_coins : Int,
_firstName: String,
_lastName:String,
_fullName:String,
_avatar:String,
_phoneNumber:String)
不是一回事。您可以在调用中包含额外元素或在签名中提供默认值。
例如
init(_objectId : String ,
_pushId : String?,
_createdAt : Date,
_updatedAt : Date,
_coins : Int = 0,
_firstName: String,
_lastName:String,
_fullName:String = "",
_avatar:String = "",
_phoneNumber:String = "")
还要确保拼写正确,因为所谓的 _firstname
与签名 _firstName
不同。
也是风格点。 _
字符在方法签名中是特殊的,因此虽然 _firstName
是一个合法的签名,但对于任何未来的 reader 来说都会让人感到困惑。您是否打算使用 _ firstName: String
来使参数名称不是必需的?或者只是 firstName: String
这将是一种正常的风格。