title: CoreData Swift and transient attribute getters
body: <p>Any advice on implementing calculated attributes when using Core Data in Swift?</p>
  
  <p>with the generated ManagedObject class, I tried to override the getter but I get the error:</p>
  
  <blockquote>
    <p>'NSManaged' not allowed on computed properties</p>
  </blockquote>
  
  <p>which implies you cannot override the getter for a transient (calculated) attribute.</p>
  
  <p>In the code sample below, <code>dateDue</code> is defined as a transient attribute in my model.</p>
  
  <p>Please note that the @NSManaged lines were generated by Xcode - not added by me.</p>
  
  <pre><code>@NSManaged var timeStamp: NSDate
  @NSManaged var dateDue: String { 
      get {
  
          self.willAccessValueForKey("dateDue")
          var ddtmp  = self.primitiveValueForKey("dateDue") as String?
          self.didAccessValueForKey("dateDue")
  
          if (ddtmp == nil)
          {
  
              let calendar = NSCalendar.currentCalendar()
  
              let components = calendar.components((NSCalendarUnit.YearCalendarUnit | NSCalendarUnit.MonthCalendarUnit ) , fromDate: self.timeStamp)
              ddtmp = "\(components.year * 1000 + components.month)"
              self.setPrimitiveValue(ddtmp, forKey: "dateDue")
  
          }
  
  
  
          return ddtmp!
      }
  
  }
  </code></pre>