title: Read-only and non-computed variable properties in Swift
body: <p>I'm trying to figure out something with the new Apple Swift language. Let's say I used to do something like the following in Objective-C. I have <code>readonly</code> properties, and they cannot be individually changed. However, using a specific method, the properties are changed in a logical way.</p>
  
  <p>I take the following example, a very simple clock. I would write this in Objective-C. </p>
  
  <pre><code>@interface Clock : NSObject
  
  @property (readonly) NSUInteger hours;
  @property (readonly) NSUInteger minutes;
  @property (readonly) NSUInteger seconds;
  
  - (void)incrementSeconds;
  
  @end
  
  @implementation Clock
  
  - (void)incrementSeconds {
       _seconds++;
  
       if (_seconds == 60) {
          _seconds = 0;
          _minutes++;
  
           if (_minutes == 60) {
              _minutes = 0;
              _hours++;
          }
      }
  }
  
  @end
  </code></pre>
  
  <p>For a specific purpose, we cannot touch the seconds, minutes and hours directly, and it's only allowed to increment second by second using a method. Only this method could change the values by using the trick of the instance variables.</p>
  
  <p>Since there are no such things in Swift, I'm trying to find an equivalent. If I do this:</p>
  
  <pre><code>class Clock : NSObject {
  
      var hours:   UInt = 0
      var minutes: UInt = 0
      var seconds: UInt = 0
  
      func incrementSeconds() {
  
          self.seconds++
  
          if self.seconds == 60 {
  
              self.seconds = 0
              self.minutes++
  
              if self.minutes == 60 {
  
                  self.minutes = 0
                  self.hours++
              }
          }
      }
  }
  </code></pre>
  
  <p>That would work, but anybody could change directly the properties.</p>
  
  <p>Maybe I already had a bad design in Objective-C and that's why the potential new Swift equivalent is not making sense. If not and if someone have an answer, I would be very grateful ;)</p>
  
  <p>Maybe the future <strong>Access Control Mechanisms</strong> promised by Apple is the answer?</p>
  
  <p>Thanks!</p>