I have the following code:
protocol User {
var photo: Int { get }
}
protocol Relationship {
associatedtype Member: User
var first: Member { get }
var second: Member { get }
}
protocol Friend: User {
var a: Int { get }
}
protocol Lover: User {
var b: String { get }
}
protocol Friendship: Relationship
where Member: Friend {
var c: String { get }
}
protocol Love: Relationship
where Member: Lover {
var d: String { get }
}
enum RelationshipRecord<F, L>: Relationship
where F: Friendship, L: Love {
case friendship(value: F)
case love(value: L)
typealias Member = User
var first: Member {
switch self {
case .friendship(let o): return o.first
case .love(let o): return o.first
}
}
var second: Member {
switch self {
case .friendship(let o): return o.second
case .love(let o): return o.second
}
}
}
As a result of compilation I have the following error:
error: type 'RelationshipRecord' does not conform to protocol 'Relationship'
enum RelationshipRecord<F, L>: Relationship
and notes:
note: possibly intended match 'RelationshipRecord.Member' (aka 'User') does not conform to 'User'
typealias Member = User
,
note: protocol requires nested type 'Member'; do you want to add it?
associatedtype Member:
After problem investigation, I know that changing User from protocol to class make code compilable.
class User {
var photo: Int { return 0 }
}
But it isn't that what I need.
Is it possible to save both: 1) User as protocol and 2) architecture from the example?
If it isn't, Why?