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

时间:2019-12-28 21:16:24

标签: swift constraints protocols

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

services.TryAddSingleton<IActionResultExecutor<ViewResult>, MyViewResultExecutor>();

但是它会引发编译错误,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 } } 我做错了吗?实现此目的的最佳方法是什么?

1 个答案:

答案 0 :(得分:3)

Self.Item替换为Self.Element