Junior — Middle
Is it possible to define a property in a protocol interface?
sobes.tech AI
Answer from AI
Yes, in Swift, properties can be defined in protocols. You can specify whether they are read-only (get) or read-write (get set).
Example:
protocol SomeProtocol {
var name: String { get set } // read-write property
var id: Int { get } // read-only property
}
Classes, structures, or enumerations that conform to this protocol must provide implementations for these properties.