O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

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

The request protocol

First, we need to define a protocol for our request models:

protocol RequestProtocol {     subscript(key: String) -> (String?, String?) { get } } extension RequestProtocol {     func getPropertyNames()-> [String] {         return Mirror(reflecting: self).children.filter {             $0.label != nil             }.map {                 $0.label!         }     } } 

Here, we defined a protocol and we extended the protocol to be able to reflect the object and get properties and their values.

Also, we added a subscript to our protocol, which any struct that wants to conform to this protocol should implement.

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