A Swift protocol requirement that can only be satisfied by using a final class

前端 未结 4 998
不知归路
不知归路 2020-12-05 18:41

I\'m modeling a owner/ownee scheme on Swift:

class Owner {
     // ...
}

protocol Ownee {
    var owner: Owner { get }
}
         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-05 19:19

    The following syntax should support what you're after:

    protocol Ownee {
        associatedtype Owned = Self where Owned:Ownee
        var owner: Owner { get }
    }
    

    (tested using Swift 4 - Beta 1)

提交回复
热议问题