Last active
July 14, 2018 06:35
-
-
Save hitendradeveloper/9bf74a004b046de6d7898f18869451e1 to your computer and use it in GitHub Desktop.
Protocol Example - 2 : Medium blog
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
import Foundation | |
protocol Displayable { | |
func displayName() | |
} | |
class Person { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} | |
} | |
extension Person: Displayable { | |
func displayName(){ | |
print("I am \(self.name).") | |
} | |
} | |
//How to use? (playground) | |
let iOSDev = Person(name: "Hitendra iDev") | |
iOSDev.displayName() //This will display "I am Hitendra iDev" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is just a simple protocol and class example for the medium blog - Protocol - The power of Swift
https://medium.com/p/950c85bb69b1