2016-01-30 80 views
0

我已經廣泛研究了這一點。在聽到有關Parse的消息後,我一直在用Kinvey爲我的BaaS玩弄。我試圖保存一個對象,但收到與KCSPersistable有關的錯誤。KCSPersistable與迅速錯誤

class Event : NSObject{ 
     var entityId: String? //Kinvey entity _id 
     var name: String? 
     var date: NSDate? 
     var location: String? 
     var metadata: KCSMetadata? //Kinvey metadata, optional 
    } 



    func hostToKinveyPropertyMapping() -> [NSObject : AnyObject]! { 
     return [ 
      "entityId" : KCSEntityKeyId, //the required _id field 
      "name" : "name", 
      "date" : "date", 
      "location" : "location", 
      "metadata" : KCSEntityKeyMetadata //optional _metadata field 
      ] 
     } 

由於超類的原因,Swift稱它爲多餘的NSObject。我刪除了KCSPersistable聲明並且代碼將成功構建,但是現在我收到以下錯誤:

'Object "<KinveyPractive.Event: 0x7fed18d484c0>" of type "KinveyPractive.Event" does not implement 'hostToKinveyPropertyMapping', a required 'KCSPersistable' method for saving the object to the backend' 

我遇到了問題循環。如果我刪除KCSPersistable,Xcode會詢問它。但是,如果我離開它,Xcode將無法編譯。

回答

0

您看到的問題是因爲Kinvey中的NSObjects隱式實現了KCSPersistable。

我們更正了我們的文檔以反映這一點。 請使用以下樣本代替您的代碼 -

class Event : NSObject { 

    var entityId: String? //Kinvey entity _id 
    var name: String? 
    var date: NSDate? 
    var location: String? 
    var metadata: KCSMetadata? //Kinvey metadata, optional 

    override func hostToKinveyPropertyMapping() -> [NSObject : AnyObject]!  { 
     return [ 
      "entityId" : KCSEntityKeyId, //the required _id field 
      "name" : "name", 
      "date" : "date", 
      "location" : "location", 
      "metadata" : KCSEntityKeyMetadata //optional _metadata field 
     ] 
    } 

}