Skip to content

Instantly share code, notes, and snippets.

@Pretz
Created September 29, 2015 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pretz/c222aab9a19e2af6fd10 to your computer and use it in GitHub Desktop.
Save Pretz/c222aab9a19e2af6fd10 to your computer and use it in GitHub Desktop.
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