Protocol
“Classes, enumerations, and structs can all adopt protocols.”
protocol ExampleProtocol {
    var simpleDescription: String { get }
    mutating func adjust()
}
struct SimpleStructure: ExampleProtocol {
    var simpleDescription: String = "A simple structure"
    mutating func adjust() {
        simpleDescription += " (adjusted)"
    }
}
“ mutating keyword in the declaration of SimpleStructure to mark a method that modifies the structure.”
 
 
0 comments:
Post a Comment