Swift Tutorial - Tutorialspoint

(backadmin) #1
protocol tcpprotocol {
init(aprot: Int)
}

Class Implementations of Protocol Initializer Requirements


Designated or convenience initializer allows the user to initialize a protocol to conform its
standard by the reserved 'required' keyword.


class SomeClass: SomeProtocol {
required init(someParameter: Int) {
// initializer implementation statements
}
}

protocol tcpprotocol {
init(aprot: Int)
}

class tcpClass: tcpprotocol {
required init(aprot: Int) {
}
}

Protocol conformance is ensured on all subclasses for explicit or inherited implementation
by 'required' modifier.


When a subclass overrides its super class initialization requirement it is specified by the
'override' modifier keyword.


protocol tcpprotocol {
init(no1: Int)
}

class mainClass {
var no1: Int // local storage
init(no1: Int) {
self.no1 = no1 // initialization
}
}
Free download pdf