
对于使用 类 扩展类型数组,以下内容对我有用(Swift 2.2 )。例如,对类型化数组进行排序:
class HighScoreEntry { let score:Int}extension Array where Element == HighScoreEntry { func sort() -> [HighScoreEntry] { return sort { struct.score < .score } }}尝试使用 typealias 或 *** 作 执行此
Type 'Element' constrained to a non-protocol type 'HighScoreEntry'将产生错误:
更新
非类 :
要使用
typealias HighScoreEntry = (Int)extension SequenceType where Generator.Element == HighScoreEntry { func sort() -> [HighScoreEntry] { return sort { Swift 3中, < } }} 扩展类型化数组,请使用以下方法:extension Sequence where Iterator.Element == HighScoreEntry { // ...}在 某些类型已重命名:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)