title: Swift inefficient table view model?
body: <p>My syntax here is probably a little inefficient, and my approach to sorting data for presentation in a table view might also need revision.</p>
  
  <p>Any tips on improving efficiency here would be much appreciated. My table view model will be an instance of this class called 'session details'</p>
  
  <pre><code>class SessionDetails {
  
      // session -&gt; registration -&gt; person
  
      let session: Session
      private var _attendees: [Person]?
      var attendees: [Person] {
          get {
              if _attendees == nil {
              if let collection = self.session?.registrations {
                  let sort = NSSortDescriptor(key: "created", ascending: true)
                  if let registrations = collection.sortedArrayUsingDescriptors([sort]) as? [Registration] {
                      var collector = [Person]()
                      for registration in registrations {
                          if registration.person != nil {
                              collector.append(registration.person!)
                          }
                      }
                      _attendees = collector
                  }
              }
              return _attendees!
          }
      }
  
      init(session: Session) {
          self.session = session
      }
  
      // rest of class truncated
  </code></pre>
  
  <p>EDIT: session, registrations and person are NSManagedObjects. A session has an NSSet of registrations. A registration has a one-to-one with Person.  So in other words, many people can register for a session.</p>