Skip to content

Instantly share code, notes, and snippets.

@PeteC
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save PeteC/b034ec34ce654c2e41b1 to your computer and use it in GitHub Desktop.

Select an option

Save PeteC/b034ec34ce654c2e41b1 to your computer and use it in GitHub Desktop.

Revisions

  1. PeteC revised this gist Aug 27, 2014. 1 changed file with 0 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -14,14 +14,6 @@ else {
    println("Different")
    }

    switch enumValueA {
    case enumValueB:
    println("Same")

    default:
    println("Different")
    }




  2. PeteC revised this gist Aug 27, 2014. 1 changed file with 8 additions and 17 deletions.
    25 changes: 8 additions & 17 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -31,24 +31,15 @@ enum AnotherEnum {
    }

    func ==(a:AnotherEnum, b:AnotherEnum) -> Bool {
    switch(a) {
    case .StateA:
    switch b {
    case .StateA:
    return true

    default:
    return false
    }
    switch (a, b) {
    case (.StateA, .StateA):
    return true

    case let .StateB(intA):
    switch b {
    case let .StateB(intB):
    return intA == intB

    default:
    return false
    }
    case let (.StateB(intA), .StateB(intB)):
    return intA == intB

    default:
    return false
    }
    }

  3. PeteC revised this gist Aug 27, 2014. 1 changed file with 24 additions and 9 deletions.
    33 changes: 24 additions & 9 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -30,21 +30,36 @@ enum AnotherEnum {
    case StateB(Int)
    }

    func ==(a:AnotherEnum, b:AnotherEnum) -> Bool {
    switch(a) {
    case .StateA:
    switch b {
    case .StateA:
    return true

    default:
    return false
    }

    case let .StateB(intA):
    switch b {
    case let .StateB(intB):
    return intA == intB

    default:
    return false
    }
    }
    }


    let anotherEnumValueA = AnotherEnum.StateA
    let anotherEnumValueB = AnotherEnum.StateB(1)

    if anotherEnumValueA == anotherEnumValueB { // Compiler error
    if anotherEnumValueA == anotherEnumValueB {
    println("Same")
    }
    else {
    println("Different")
    }

    switch anotherEnumValueA {
    case anotherEnumValueB: // Compiler error - doesn't conform to protocol IntervalType
    println("Same")

    default:
    println("Different")
    }

  4. PeteC revised this gist Aug 27, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,14 @@ else {
    println("Different")
    }

    switch enumValueA {
    case enumValueB:
    println("Same")

    default:
    println("Different")
    }




  5. PeteC revised this gist Aug 27, 2014. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -14,14 +14,6 @@ else {
    println("Different")
    }

    switch anotherEnumValueA {
    case anotherEnumValueB: // Compiler error - doesn't conform to protocol IntervalType
    println("Same")

    default:
    println("Different")
    }




    @@ -40,3 +32,11 @@ else {
    println("Different")
    }

    switch anotherEnumValueA {
    case anotherEnumValueB: // Compiler error - doesn't conform to protocol IntervalType
    println("Same")

    default:
    println("Different")
    }

  6. PeteC revised this gist Aug 27, 2014. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,15 @@ else {
    println("Different")
    }

    switch anotherEnumValueA {
    case anotherEnumValueB: // Compiler error - doesn't conform to protocol IntervalType
    println("Same")

    default:
    println("Different")
    }




    enum AnotherEnum {
  7. PeteC revised this gist Aug 27, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ enum AnotherEnum {
    }

    let anotherEnumValueA = AnotherEnum.StateA
    let anotherEnumValueB = AnotherEnum.StateB
    let anotherEnumValueB = AnotherEnum.StateB(1)

    if anotherEnumValueA == anotherEnumValueB { // Compiler error
    println("Same")
  8. PeteC created this gist Aug 27, 2014.
    33 changes: 33 additions & 0 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    enum MyEnum {
    case StateA
    case StateB
    }


    let enumValueA = MyEnum.StateA
    let enumValueB = MyEnum.StateB

    if enumValueA == enumValueB {
    println("Same")
    }
    else {
    println("Different")
    }



    enum AnotherEnum {
    case StateA
    case StateB(Int)
    }

    let anotherEnumValueA = AnotherEnum.StateA
    let anotherEnumValueB = AnotherEnum.StateB

    if anotherEnumValueA == anotherEnumValueB { // Compiler error
    println("Same")
    }
    else {
    println("Different")
    }