Optional protocol methods in Swift

In Swift it’s kind of unsupported to implemented optional protocol methods. You can, which is ugly, use the @objc syntax: @objc protocol MyProtocol { optional func doSomething(); } class MyClass : MyProtocol { // no error } Another disadvantage here is that structs are unsupported, as you’re bridging for Objc. Using protocol extensions to create … 

 

Protocol extensions and typed arrays

Swift 2.0 introduces protocol extensions, aswel as typed array extensions. This makes it possible to extend an array containing a specific type or even add methods to class inheriting a specific protocol. Typed array protocol extensions With typed array extensions you can create methods for Arrays containing a specific type only. For example, if you …