Protocol - Delegate

 



protocol HandleCallbackProtocal {

    func callback1()

    func callback2()

}


class ProtocolClass {

    var delegate: HandleCallbackProtocal?

    

    func call1() {

        delegate?.callback1()

    }

}


class ClassP: HandleCallbackProtocal {

    func callback1() {

        

    }

    

    func callback2() {

        

    }

    

    init() {

        let obj = ProtocolClass()

        obj.delegate = self

        

        obj.call1()

    }

}






Ref. Links

Swift: Why You Should Avoid Using Default Implementations in Protocols




Comments

Popular posts from this blog

SubString in Swift

PUSH Notification