Kodeco Forums

RWDevCon 2016 Session 303: Introduction to Protocol-Oriented Programming

Swift 2 protocols can do things impossible in Objective C, so much that Apple has even argued for “Protocol-Oriented Programming” as an alternative to object-oriented programming. What does this really mean and when is it wise? This talk will walk through a detailed example, illustrating the pros and cons of OOP and protocol-based modeling, to show where Swift protocols are strictly superior, and also where their new benefits introduce fundamental new tradeoffs.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1289-rwdevcon-2016-session-303-introduction-to-protocol-oriented-programming

Great presentation! PATs are still something I’m wrapping my head around. It’s one of those things where when it works, you’re not exactly sure how but happy that it does work :wink:

I followed all the steps in the lab, but am curious how you would use the last (generic) function with different types of ScalarMultipliable3’s:

func multiplyAllMultiples<T: ScalarMultipliable3>(values: [T], factor: Float) -> [T] { return values.map({ $0.times(factor) }) }

Swift doesn’t seem to like calling that function like so:

multiplyAllMultipliables([MyScalar3(value: 3), MyVector3(value: [2, 4])], factor: 2)

But works fine with:

multiplyAllMultipliables([MyScalar3(value: 2), MyScalar3(value: 4)], factor: 2)

I would have guessed that as long as I’m passing an array of ScalarMultipliable3’s, the function would return the multiplied output.

Wondering if you can lend some insight on why that doesn’t seem to be the case.

Thanks again for the awesome presentation!

Hi Alexis,
Just looking at the video version of your talk. I’m trying to follow along. At 6:14 of the video you refer to a file that gives more context called RWDevCon2016-ProtocolOrientedProgramming.playground in the SourceAssets folder. I don’t see this file. The file that is there is causing an error when I try to open it. It’s called POPPastePlayground.playground and the error is “couldn’t load settings from contents.xcplayground” . Anyhow, any chance you could upload the file you refer to there. Seems kinda key.

Ok, never mind. I solved it. I did a showpackages and the playground was buried inside there. It seems to run after a couple of tries.