I wanted to create a protocol which represents an AsyncSequence
with a primary associated type, so I followed the guidance given in, for example, this post, and wrote:
struct Message {
var text: String
}
protocol PrimaryAssociatedTypeAsyncSequence<Element>: AsyncSequence {
}
func use(_ sequence: any PrimaryAssociatedTypeAsyncSequence<Message>) async throws {
for try await message in sequence {
print(message.text)
}
}
However, this gives the following compiler error:
/Users/lawrence/Desktop/async-sequence-protocols/Sources/async-sequence-protocols/async_sequence_protocols.swift:13:23: error: value of type 'Any' has no member 'text'
print(message.text)
~~~~~~~ ^~~~
/Users/lawrence/Desktop/async-sequence-protocols/Sources/async-sequence-protocols/async_sequence_protocols.swift:13:23: note: cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members
print(message.text)
^
( as AnyObject)
Am I doing something wrong?