2015-11-27 160 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) 
      }     
     } 
    }