Hello,
I recently wrote my first macro that is supposed to expand a given protocol of a data model with a type for a network response. For simplicity lets say that the macro adds a peer struct to the model that conforms to Identifiable
and has an additional id
property next to the properties the protocol defined. Also an extension with a typealias is added. It would look something like this:
@PublicModel
protocol Person {
var name: String { get }
var age: Int { get }
}
And would expand to:
protocol Person {
var name: String { get }
var age: Int { get }
}
struct PublicPerson: Codable, Identifiable {
let id: UUID
let name: String
let age: Int
init(id: UUID, name: String, age: Int) {
self.id = id
self.name = name
self.age = age
}
}
extension Person {
typealias Public = PublicPerson
}
Now if I add some code to the file that makes use of the added type and typealias like:
struct AddressBook {
var people: [Person.Public]
}
let myContacts = AddressBook(people: [
Person.Public(id: UUID(), name: "Peter", age: 24),
Person.Public(id: UUID(), name: "Max", age: 25),
Person.Public(id: UUID(), name: "Lena", age: 23)
])
It compiles just fine.
But as soon as the model definition and usage part are split into separate files I get an error in the usage part that complains that: 'Public' is not a member type of protocol 'Person'.
Is this to be expected?