You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letpythons=["Eric","Graham","John","Michael","Terry","Terry"]letbeatles=Set(["John","Paul","George","Ringo"])extensionCollection{func summarize(){print("There are \(count) of us:")
for name in self{print(name)}}}
pythons.summarize()
beatles.summarize()
Protocol-oriented programming
protocolIdentifiable1{varid:String{getset}func identify()}extensionIdentifiable1{func identify(){print("My ID is \(id).")}}structUser1:Identifiable1{varid:String}lettwostraws=User1(id:"twostraws")
twostraws.identify()
Protocols and extensions summary
Protocols describe what methods and properties a conforming type must have, but don’t provide the implementations of those methods.
You can build protocols on top of other protocols, similar to classes.
Extensions let you add methods and computed properties to specific types such as Int.
Protocol extensions let you add methods and computed properties to protocols.
Protocol-oriented programming is the practice of designing your app architecture as a series of protocols, then using protocol extensions to provide default method implementations.