equatable

    0熱度

    1回答

    建立在this question of mine(和接受的答案)上,我想測試一個數組中的值的包含。 該值存儲在類型爲Any的變量中,數組被定義爲[Any]。 實際類型存儲在變量和數組中的元素的值的在運行時決定的,但保證滿足下列條件: 這兩種類型的(變量和數組元素)重合,和 它們是String,Int或Bool之一。 到目前爲止,我得到這個代碼的工作: var isContained = false

    6熱度

    3回答

    我們有一個簡單的類Person固有的領域Object。 現在我們希望該子類符合Equatable協議。非常簡單的代碼看起來像這樣。 class Person: Object, Equatable { dynamic var localID = "0" dynamic var name:String? } func ==(lhs: Person, rhs: Person

    10熱度

    2回答

    我試圖在基類中實現==運算符(從Equatable),並且它的子類在Swift 3中。所有類將只在Swift中使用,所以我不想涉及NSObject或NSCopying協議。 我開始用一個基類和子類: class Base { var x : Int } class Subclass : Base { var y : String } 現在我想添加Equatable和

    3熱度

    2回答

    我想用struct作爲字典的鍵。代碼適用於swift 2,但不適用於swift 3和圖片鏈接。 Equatable Code : Picture

    1熱度

    2回答

    我有一個自定義類(VotingOption)從NSManagedObject繼承,有時我要檢查,如果陣列中的一些投票選項是重複的。我正在儘可能使我的代碼儘可能通用。這就是我所做的擴展CollectionType協議: extension CollectionType where Self.Generator.Element : Equatable { var duplicates: [

    -1熱度

    2回答

    在我的應用程序中,我有一個類Video,它實現Equatable協議,因爲我需要使用==(lhs:,rhs:) -> Bool函數。我的班是因爲這樣: class Video: Equatable { var url: URL! // Some other vars } func ==(lhs: Video, rhs: Video) -> Bool { retu

    4熱度

    2回答

    我在編譯時在Equatable中出現錯誤。 我想在列表中添加find或contains方法來檢查值。 我的代碼下面 class Generic: NSObject, Equatable, NSCoding //Am Having an error - Redundant conformance of 'Generic' to protocol 'Equatable' { var g

    2熱度

    1回答

    包含方法不能正常工作,即使它與Object匹配,它也給我提供了錯誤結果? 我的代碼下面 class Generic: NSObject, NSCoding { var genericCode: String? var genericName : String? var genericType : String? var genericImageUrl :

    1熱度

    1回答

    我有以下枚舉: enum Message: ErrorType { case MessageWithInfo(info:String?) case MessageDidFail case MessageDidSend(info:String) case InvalidMessageData case MessageWithDelay(delay:D

    6熱度

    3回答

    我有一點問題.. 如何使一個結構符合協議「Equatable」? 我使用的Xcode 7.3.1 我的代碼: struct MyStruct { var id: Int var value: String init(id: Int, value: String) { self.id = id self.value = value }