O'Reilly logo

Transitioning to Swift by Scott Gardner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter    8

Defining and Adopting Protocols

Swift is predominantly a protocol-based language. Protocols are also prevalent in Objective-C, frequently used with the delegation design pattern—although there has been a gradual shift from protocol/delegate to block-based usage in recent years. A protocol is simply a contract that defines requirements that the adopting type agrees to implement. This chapter will compare how Objective-C and Swift similarly utilize protocols, pointing out the differences in syntax and examining the broadened usage, new capabilities, and specific caveats of using protocols in Swift.

Use Cases

Protocols are used similarly in Objective-C and Swift to set the expected behavior of a class or type. A protocol accomplishes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required