Skip to content

Instantly share code, notes, and snippets.

@below
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save below/475cdfd44550496e0aff to your computer and use it in GitHub Desktop.
Save below/475cdfd44550496e0aff to your computer and use it in GitHub Desktop.
import UIKit
protocol myProtocol {
func dothatthing () -> Void
}
var array : [protocol<myProtocol>] = []
class A : myProtocol {
func dothatthing() {
println("Class A")
}
}
let foo = A()
let bar = A()
array.append(foo)
array.append(bar)
for x in array {
// The following does not compute
if x === bar {
println("We got it!")
}
else {
println("We have not it")
}
}
@kodierwerk
Copy link

import UIKit

protocol myProtocol {
func dothatthing () -> Void
}

var array : [protocol] = []

class A : myProtocol {
func dothatthing() {
println("Class A")
}
}

let foo = A()
let bar:A = A()
array.append(foo)
array.append(bar)

for x in array {
// The following does compute

let test = x as? A

if bar === test {
    println("We got it!")
}else{
    println("We have not it")
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment