我有这个错误:
无法将“User”类型的返回表达式转换为返回类型“User?”
var CURRENT_USER: User? {
if let currentUser = Auth.auth().currentUser {
return currentUser
}
return nil
}
User
声明:
class User {
var email: String?
var ProfileImageUr: String?
var username: String?
var id: String?
}
extension User {
static func transForUser(dict: [String: Any], key: String) -> User {
let user = User()
user.email = dict["email"] as? String
user.ProfileImageUr = dict["ProfileImageUr"] as? String
user.username = dict["username"] as? String
user.id = key
return user
}
}
这样做可以返回未包装的用户。
尝试
return Auth.auth().currentUser
代替
if let currentUser = Auth.auth().currentUser {
return currentUser
}
return nil