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. You can think of a protocol like a contract that every conforming type agrees to. This allows you to code against that contract without concerning yourself with specific types.
Define a protocol that specifies the interface you need for the printTable(_:withColumnLabels:)
function.
The function needs to know how many rows and columns there are, what the label for each column is, and what data should be displayed in each cell.
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, just before ...
Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.