I'm experimenting with Swift protocols, and I've run into something funny. There are lots of workarounds, but can anyone explain the error below?
protocol UserRenderable {
var name : String { get }
}
protocol PostRenderable {
var title: String { get }
var author: UserRenderable { get }
}
struct User {
let id: String
let name : String
}
struct Post {
let id: String
let title: String
let author: User
}
extension User : UserRenderable {}
extension Post: PostRenderable {}
The above code (drop it in a playground, or whatever) will throw a compilation error:
protocol requires property 'author' with type 'UserRenderable'; do you want to add a stub?
var author: UserRenderable { get }
What's the reason for this?