O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

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

Property requirements

A protocol can require that the conforming type provides certain properties with a specified name and type. The protocol does not say if the property should be a stored or computed property because the implementation details are left up to the conforming type.

When defining a property within a protocol, we must specify whether the property is a read-only or a read-write property by using the get and set keywords. Let's look at how we would define properties within a protocol by creating a protocol named FullName:

protocol FullName {  var firstName: String { get set }  var lastName: String { get set }} 

The FullName protocol defines two properties, which any type that conforms to the protocol must implement. These are the ...

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