🅿️protocol
🚧 施工中
what is protocol?
protocol is a declaration.
Protocol Requirements:
methods
initializers
associated types
properties
inherited protocols
Any
is an empty protocol and everything implicitly conforms to this protocol. 👉 AppVenture.me
// Some code
protocol SomeProtocol {
// -----------------------------
// Property Requirements
// -----------------------------
// • can be stored/computed property
// ⭐ gettable
// can’t be fulfilled by a constant stored property
// or a read-only computed property.
var mustBeSettable: Int { get set }
// ⭐ settable
// satisfied by any kind of property
var doesNotNeedToBeSettable: Int { get }
// ⭐ type property
static var typeProperty: Int { get set }
// -----------------------------
// Method Requirements
// -----------------------------
func method() -> Double // ⭐ instance method
static func typeMethod() // ⭐ type method
mutating func toggle() // ⭐ mutating method
// -----------------------------
// Init Requirements
// -----------------------------
init(someParameter: Int)
}
Swift ⟩ Protocols
Last updated