0

I'm a little bit confused with this.

We have variables in swift that can have a setter, getter or both and constants which can't change his own initial value,

So, is a var with only a getter the same as a let? If it is, what is the idea in a protocol to set a variable like this

protocol myProtocolA {
    var myString: String {get}
}

vs

protocol myProtocolB {
    let myString: String {get} //I don't think this will compile but I'm curious
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3175133
  • 325
  • 3
  • 8
  • 2
    *"I don't think this will compile"* - try it. What happens? – rmaddy Jan 11 '17 at 03:35
  • let declarations cannot be computed properties – Leo Dabus Jan 11 '17 at 03:35
  • I tried to explain it best I could, but it seems there are documents that write out how it all works by [Apple](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html) – Ben Ong Jan 11 '17 at 03:53
  • This question [Swift Protocol get only settable](http://stackoverflow.com/questions/30573872/swift-protocol-get-only-settable) seems to answer your query – Ben Ong Jan 11 '17 at 04:03

0 Answers0