What do I need to add to extend the UserModel with AuthenticatedUserModel without getting this error?
// 'required' initializer 'init(from:)' must be provided by subclass of 'UserModel'
I know I can also just add the accessToken to the UserModel as optional but I want to understand what's going on so I can understand swift a bit better?
class UserModel: Codable, Identifiable, ObservableObject {
let id: Int
let firstName: String?
let lastName: String?
let username: String?
let bio: String?
let theme: String?
let imageSrc: String?
let interests: [String]?
let followerCount: Int?
let following: Bool?
let followingCount: Int?
let hasCompletedRegistration: Bool?
let isPrivate: Bool?
let readerMode: Bool?
let isActive: Bool?
let isVerified: Bool?
let isSuspended: Bool?
let isAdmin: Bool?
let isFollowing: Bool?
let createdAt: String?
let updatedAt: String?
init(id: Int, firstName: String, lastName: String, bio: String) {
self.id = id
self.firstName = firstName
self.lastName = lastName
self.username = ""
self.bio = ""
self.theme = ""
self.imageSrc = ""
self.interests = [""]
self.followerCount = 0
self.following = false
self.followingCount = 0
self.hasCompletedRegistration = true
self.isPrivate = false
self.readerMode = true
self.isActive = true
self.isVerified = false
self.isSuspended = false
self.isAdmin = false
self.isFollowing = false
self.createdAt = ""
self.updatedAt = ""
}
var name: String {
return "\(firstName ?? "") \(lastName ?? "")"
}
}
class AuthenticatedUserModel: UserModel {
let accessToken: String?
override init(id: Int, firstName: String, lastName: String, bio: String) {
self.accessToken = nil
super.init(id: id, firstName: firstName, lastName: lastName, bio: bio)
}
}