Created
June 27, 2018 15:38
-
-
Save gbasile/1d179d3af955562a66eb3a9f849b7d68 to your computer and use it in GitHub Desktop.
Be careful when providing default implementations to your protocols
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
import Foundation | |
protocol People { | |
var eat: String { get } // 1) try to comment this | |
var dislike: String { get } // 2) Try to comment this | |
} | |
//3) Try to rename one of the above | |
extension People { | |
var eat: String { | |
return "Pineapple Pizza" | |
} | |
var dislike: String { | |
return "Vespa" | |
} | |
} | |
struct Giuseppe: People { | |
var eat: String { | |
return "Margherita" | |
} | |
var dislike: String { | |
return "Pineapple" | |
} | |
} | |
let giuseppe: Giuseppe = Giuseppe() | |
print("Real Giuseppe eat: \(giuseppe.eat)") | |
print("Real Giuseppe dislike: \(giuseppe.dislike)") | |
let fakeGiuseppe: People = Giuseppe() | |
print("Fake Giuseppe eat: \(fakeGiuseppe.eat)") | |
print("Fake Giuseppe dislike: \(fakeGiuseppe.dislike)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment