Replacement for array's indexOf(_:) method in Swift 3

后端 未结 3 903
小蘑菇
小蘑菇 2021-02-01 03:20

In my project (written in Swift 3) I want to retrieve index of an element from array using indexOf(_:) method (existed in Swift 2.2), but I cannot find any replacem

3条回答
  •  面向向阳花
    2021-02-01 04:09

    Didn't work for me in Swift 3 XCode 8 until I gave my class an extension.

    For example:

    class MyClass {
        var key: String?
    }
    
    extension MyClass: Equatable {
        static func == (lhs: MyClass, rhs: MyClass) -> Bool {
            return MyClass.key == MyClass.key
        }
    }
    

提交回复
热议问题