Essentially protocols are very similar to Java interfaces except for:
- Swift protocols can also specify properties that must be implemented (i.e. fields)
- Swift protocols need to deal with value/reference through the use of the mutating keyword (because protocols can be implemented by structures, enumerations or classes).
- you can combine protocols at any point using “Protocol Composition”. This replaces the older swift
protocol<A, B>way of protocol composition. For example, declaring a function parameter that must adhere to protocolNamedandAgedas:
func wishHappyBirthday(to celebrator: Named & Aged) {}
These are the immediately apparent differences for a Java developer (or at least what I’ve spotted so far). There’s more info here.