Posts

Showing posts with the label delegate property

Swift 3: Protocol Part 3

As I alluded to details about the protocol in two-part ( Protocol Part1 and Protocol Part 2 ) previous posts. Now this my last post with some more information about the protocol. All code example tested on Xcode 8.1. Class-Only Protocols: we can stop the protocol adoption to class types by putting class keywords in the protocol inheritance list. This class always should be in first place in the protocols inheritance list, before if the type is going to inherit any other protocol. protocol ClassOnlyProtocol : class , myProtocol { } In this ClassOnlyProtocol can be adopted by class types only if any enum and structure try to write any definition which tries to adopt protocol will end up with a compile-time error. Protocol Composition With the help of protocol composition, we can create a single requirement that could combine multiple protocols. It can use a require a type to conform to multiple protocols at once. protocol FirstName {     var firstName ...

Swift 3: Protocol Part 1

Introduction: Protocol main and widely used concept in objective c and swift both. So here we will be discussing in swift. We have two parts for a protocol. Part -1, will have basic terminology and concept to understand it and Part 2 and Part 3 will have some more drills in detail about it. The protocol you can think of “Contract” between two bodies. If anyone has acquired it then, that has to follow certain rules to incorporate the action of the contract. Same way Protocol in objective will act in the same way. Protocols define the set of methods, properties, and required pieces of functionality. Any type whoever going to conform it will have to conform first and then implement the requirement. The protocol can be adopted by a class, struct, enum. Any type that fulfilling the requirement of that protocol is said to conform to that protocol. If you conform to the protocol then we need to implement the requirement. We can extend the protocol as well to extend t...