Swift Array.insert generics

前端 未结 5 1669
盖世英雄少女心
盖世英雄少女心 2020-12-07 03:02
func getIndex(valueToFind: T) -> Int? {...}

mutating func replaceObjectWithObject(obj1: T, obj2: T) {
    if let index =          


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 03:24

    You can use extension with a where clause constraint and I'm using Xcode 7.3.1

    extension Array where Element: Equatable {
        func testEqutability() {
            let e1 = self[0]
            let e2 = self[1]
            if e1 == e2 {//now we can use == to test Element equtability
                //do something 
            }
        }
    }
    

提交回复
热议问题