December 2018
Intermediate to advanced
414 pages
10h 19m
English
Protocols don't provide any implementation, but that doesn't mean the only use they have is for conformance on concrete types. You can (and should) use protocols as types. Protocols are first class citizens, as are functions, classes, structures, and enums, which means you can use them anywhere you'd be able to use any other type:
You should already be very comfortable with using protocols as types. Delegation leverages this widely:
protocol RunnerDelegate: class { func didStart(runner: Runner) func didStop(runner: Runner)}class Runner { weak var delegate: RunnerDelegate? func start() ...Read now
Unlock full access