Protocols
A protocol allows you to define the interface you want a type to satisfy. A type that satisfies a protocol is said to conform to the protocol.
Define a protocol that specifies the interface you need for the printTable(_:columnLabels:data:) function. The printTable(_:columnLabels:data:) function needs to know how many rows and columns there are, what the label for each row and column is, and what the item of data to display in each cell should be. It does not matter to the Swift compiler where in your playground file you put this protocol. But it probably makes the most sense to put it at the top of the file, just before printTable(_:columnLabels:data:), because you are going to use the protocol in the function.
Listing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access