Extending typed Arrays (of primitive types like Bool) in Swift 3?

后端 未结 4 2092
别那么骄傲
别那么骄傲 2021-02-07 20:57

Previously in Swift 2.2 I\'m able to do:

extension _ArrayType where Generator.Element == Bool{
    var allTrue : Bool{
        return !self.contains(false)
    }         


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 21:18

    Apple replaced _ArrayType with _ArrayProtocol in Swift 3.0 (see Apple's Swift source code on GitHub) so you can do the same thing you did in Swift 2.2 by doing the following:

    extension _ArrayProtocol where Iterator.Element == Bool {
        var allTrue : Bool { return !self.contains(false) }
    }
    

提交回复
热议问题