2015-11-27 161 views
1

我PFUser與其他字段的子類:獲取PFUser參考對象

class User: PFUser { 

    @NSManaged var myLists:  [BuyList] 
    @NSManaged var receivedlists: [BuyList] 
    @NSManaged var users:   [User] 

    override class func initialize() { 
     struct Static { 
      static var onceToken : dispatch_once_t = 0; 
     } 
     dispatch_once(&Static.onceToken) { 
      self.registerSubclass() 
     } 
    }  
} 

BuyList是PFObject的子類。

我創建了BuyList對象,用它做了一些可怕的事情並追加到User.myLists。從那以後,我打電話:

User.currentUser()!.saveInBackground() 

在解析儀表盤我有 'myLists' 字段與此值:

[{"__type":"Pointer","className":"BuyList","objectId":"D5sGbsEhio"}] 

但設備對象是:

<BuyList: 0x7bab9b80, objectId: D5sGbsEhio, localId: (null)> { 
//Empty body here 
} 

我怎麼能接受用戶對象和它的屬性?

回答

0

我嘗試加載用戶的主屏幕打開之前,所以我換成開法:

private func openHomeScreen() {    
     self.loadList(0) {() -> Void in 
      Utils.setRootController("HomeController") 
     }    
    } 

private func loadList(var index: Int, completition:() -> Void) { 
     User.currentUser()!.myLists[index].fetchIfNeededInBackgroundWithBlock { (object: PFObject?, error: NSError?) -> Void in 
      index++ 
      if index == User.currentUser()!.myLists.count { 
       completition() 
      } else { 
       self.loadList(index, completition: completition) 
      }     
     } 
    }