2017-10-05 49 views
0

我可以這樣做:斯威夫特擴展:將在那裏和協議堅持

extension Dictionary : MyProtocol {} 

,我可以這樣做:

extension Dictionary where Key: String, Value: Int {} 

,但我不能做到這一點:

extension Dictionary where Key: String, Value: Int : MyProtocol {} 

或更多:

extension Dictionary : MyProtocol where Key: String, Value: Int {} 

格式化的正確方法是什麼,以允許我指定類型並指定遵守協議?

回答

0

好吧,我是個白癡。剛剛意識到最後一個例子給出了這個錯誤:

Extension of type 'Dictionary' with constraints cannot have an inheritance clause 

所以大概根本不可能呢。