Created
January 25, 2017 02:52
-
-
Save rydermackay/85b354100e0236d082b604b8700ab0c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Xcode 8.3b1 (8W109m) | |
import Foundation | |
struct Box<T> { | |
let value: T | |
init(value: T) { | |
self.value = value | |
} | |
init(_ value: T) { | |
self.value = value | |
} | |
} | |
@objc protocol FooDelegate { | |
func foo(_ foo: Foo, didSomethingAt index: Int) | |
} | |
class Foo: NSObject { | |
weak var delegate: FooDelegate? | |
} | |
class UseFoo: NSObject { | |
var foo: Foo! | |
func referToMemberFooAsAny() { | |
foo = Foo() | |
foo.delegate = self | |
takesAny(foo) // self.foo | |
takesArray([foo]) // self.foo(_:didSomethingAt:) | |
takesArray([foo as Foo]) // self.foo | |
takesDict(["foo": foo]) // self.foo(_:didSomethingAt:) ?! | |
takesBox(Box(value: foo)) // self.foo(_:didSomethingAt:) | |
takesBox(Box(foo)) // self.foo !?!??! | |
} | |
func takesAny(_ value: Any) { | |
print(value) | |
} | |
func takesArray(_ array: Array<Any>) { | |
print(array) | |
} | |
func takesDict(_ dict: Dictionary<String, Any>) { | |
print(dict) | |
} | |
func takesBox(_ box: Box<Any>) { | |
print(box) | |
} | |
} | |
extension UseFoo: FooDelegate { | |
func foo(_ foo: Foo, didSomethingAt index: Int) { | |
print("foo \(foo) did something at \(index)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Xcode 8.2.1 and earlier infer
self.foo
in each case.