如何为采用类型的快速协议设置约束?

问题描述 投票:0回答:1

我需要快速制作一个多级标记器,为此,我决定制作一个协议,要求该协议的采用者为字符序列。这样

protocol TokenProtocol where Self: Sequence, Self.Item == Character {
    //any token must consist of characters
    var characterRepresentation: [Character] { get }
    //but not all tokens may consist of multiple words 
    var wordRepresentaion: [String]? { get }
}

但是它引起了一个编译错误,即'Item' is not a member type of 'Self'我做错了吗?实现此目的的最佳方法是什么?

swift constraints protocols
1个回答
1
投票

Self.Item替换Self.Element

© www.soinside.com 2019 - 2024. All rights reserved.