Post

Replies

Boosts

Views

Activity

Reply to Instance member cannot be used on type; did you mean to use a value of this type instead?
I tried Employee().data however, It still came up with an error. Here is the definition of Employee: import Foundation struct Employee: Identifiable, Codable { let id: UUID var firstName: String var lastName: String var title: String var email: String init(id: UUID = UUID(), firstName: String, lastName: String, title: String, email: String) { self.id = id self.firstName = firstName self.lastName = lastName self.title = title self.email = email } } extension Employee { struct Data { var firstName: String = "" var lastName: String = "" var title: String = "" var email: String = "" } var data: Data { Data(firstName: firstName, lastName: lastName, title: title, email: email) } mutating func update(from data: Data) { firstName = data.firstName lastName = data.lastName title = data.title email = data.email } init(data: Data) { id = UUID() firstName = data.firstName lastName = data.lastName title = data.title email = data.email } } extension Employee { static let sampleData: [Employee] = [ Employee(firstName: "John", lastName: "Doe", title: "Chief Executive Officer", email: "johndoe@example.com"), Employee(firstName: "Jane", lastName: "Doe", title: "Creative Assistant", email: "janedoe@example.com"), ] }
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’23