Created
September 29, 2015 20:56
-
-
Save Pretz/c222aab9a19e2af6fd10 to your computer and use it in GitHub Desktop.
Swift Bug w/ Protocol Extensions
This file contains hidden or 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
protocol SomeValue { | |
var name: String? { get } | |
func getName() -> String? | |
} | |
extension SomeValue { | |
var name: String? { | |
return nil | |
} | |
func getName() -> String? { | |
return self.name | |
} | |
} | |
struct AValue: SomeValue { | |
let name = "bunnies" | |
} | |
struct AnotherValue: SomeValue { | |
let name: String? = "oranges" | |
} | |
let v = AValue() | |
v.name // "bunnies" | |
v.getName() // nil | |
let s: SomeValue = AValue() | |
s.name // nil | |
s.getName() // nil | |
let o: SomeValue = AnotherValue() | |
o.name // "oranges" | |
o.getName() // "oranges" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment