-3

I have this code

protocol SomeProtocol {
    var mustBeSettable: Int { get set }
    var doesNotNeedToBeSettable: Int { get }
}

And when implement the protocol in class

class example: SomeProtocol {

    doesNotNeedToBeSettable = 2

    func miFunc(word: String){

        doesNotNeedToBeSettable = 3
    }

}

Why I can modified the variable? because it is only get.

When can i use set? or set / get

nhgrif
  • 61,578
  • 25
  • 134
  • 173
Fabio
  • 1,913
  • 5
  • 29
  • 53
  • Please explain better your question, every variable in an protocol need to be implemented in every class/struct,etc that implement it, the definition of when it's read-only or not is your decision in your declaration. – Victor Sigler Apr 29 '16 at 22:14

1 Answers1

0

The rule is that a {get} protocol property may be settable, but a {get set} protocol property must be settable.

matt
  • 515,959
  • 87
  • 875
  • 1,141