I'm new to Swift and I'm having trouble returning a User? value from currentUser in Firebase for CURRENT_USER. I have my User class declaration below and it's located in a separate UserApi file. All the help is greatly appreciated!
var CURRENT_USER: User? {
if let currentUser = Auth.auth().currentUser {
return currentUser
}
return nil
}
User declaration:
class User {
var email: String?
var profileImageUrl: String?
var username: String?
var id: String?
var isFollowing: Bool?
}
extension User {
static func transformUser(dict: [String: Any], key: String) -> User {
let user = User()
user.email = dict["email"] as? String
user.profileImageUrl = dict["profileImageUrl"] as? String
user.username = dict["username"] as? String
user.id = key
return user
}
}
Since you have declared a
Usertype in your project, the wordUserinvar CURRENT_USER: User? {gets resolves to your ownUsertype, rather thanFirebaseAuth.User, which is in another module.To fix this, either:
rename your own
Userto something such asUserInfo, or;Add the prefix
FirebaseAuth.toUserto differentiate:You can also add a
typealiasto give the FirebaseUsera different name: