Skip to content

Instantly share code, notes, and snippets.

@Pretz
Created September 29, 2015 20:56
Embed
What would you like to do?
Swift Bug w/ Protocol Extensions
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