![](/img/trans.png)
[英]Cannot convert return expression of type 'User' to return type 'User?' for getting currentUser from Firebase
[英]Cannot convert return expression of type 'User' to return type '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
有兩個不同的類,都稱為User。
該解決方案只是將您的類重命名為另一個名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.