映射解析对象在 callFunctionInBackground 中不起作用
Mapping parse object doesn't work in callFunctionInBackground
这是测试云代码的样子:
Parse.Cloud.define ( "getSpokey" , function (request , response ) {
var Spokey = Parse.Object.extend("Spokey");
var query = new Parse.Query(Spokey);
query.find({
success: function(spokey){
response.success(spokey);
},
error: function(spokey, error){
response.error(error);
}
});
});
在浏览器上测试此功能时,这是 return 我得到:
{"result":[{"__type":"Object","className":"Spokey","createdAt":"2015-11-22T13:51:40.187Z","name":"kussa","objectId":"niCUOIFx3V","updatedAt":"2015-11-22T13:51:40.187Z"},{"__type":"Object","className":"Spokey","createdAt":"2015-11-22T13:51:44.592Z","name":"test","objectId":"yGm2hg2GRI","updatedAt":"2015-11-22T13:51:44.592Z"}]}
在 iOS 方面,这是 swift
中的 class 代码
class SPKSpokey : PFObject, PFSubclassing {
var name : String!
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
static func parseClassName() -> String {
return "Spokey"
}
}
在控制器中我有以下代码:
PFCloud.callFunctionInBackground("getSpokey", withParameters: nil) { (result , error) -> Void in
if let result = result as? [SPKSpokey] {
print(result)
for sp in result {
print(sp.name) //crashes here
}
}
}
在我的应用委托中我有:
SPKSpokey.registerSubClass()
执行print(result)
时控制台显示如下:
[<Spokey: 0x7f8d70c7ef60, objectId: niCUOIFx3V, localId: (null)> {
name = kussa;
}, <Spokey: 0x7f8d70c80cf0, objectId: yGm2hg2GRI, localId: (null)> {
name = test;
}]
所以我的问题是:如何在不使用 objectForKey
的 PFObject
的情况下访问我的 class 属性,例如 sp.name
尝试更改:
var name : String!
至:
@NSManaged public var name: String!
这是测试云代码的样子:
Parse.Cloud.define ( "getSpokey" , function (request , response ) {
var Spokey = Parse.Object.extend("Spokey");
var query = new Parse.Query(Spokey);
query.find({
success: function(spokey){
response.success(spokey);
},
error: function(spokey, error){
response.error(error);
}
});
});
在浏览器上测试此功能时,这是 return 我得到:
{"result":[{"__type":"Object","className":"Spokey","createdAt":"2015-11-22T13:51:40.187Z","name":"kussa","objectId":"niCUOIFx3V","updatedAt":"2015-11-22T13:51:40.187Z"},{"__type":"Object","className":"Spokey","createdAt":"2015-11-22T13:51:44.592Z","name":"test","objectId":"yGm2hg2GRI","updatedAt":"2015-11-22T13:51:44.592Z"}]}
在 iOS 方面,这是 swift
中的 class 代码class SPKSpokey : PFObject, PFSubclassing {
var name : String!
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
static func parseClassName() -> String {
return "Spokey"
}
}
在控制器中我有以下代码:
PFCloud.callFunctionInBackground("getSpokey", withParameters: nil) { (result , error) -> Void in
if let result = result as? [SPKSpokey] {
print(result)
for sp in result {
print(sp.name) //crashes here
}
}
}
在我的应用委托中我有:
SPKSpokey.registerSubClass()
执行print(result)
时控制台显示如下:
[<Spokey: 0x7f8d70c7ef60, objectId: niCUOIFx3V, localId: (null)> {
name = kussa;
}, <Spokey: 0x7f8d70c80cf0, objectId: yGm2hg2GRI, localId: (null)> {
name = test;
}]
所以我的问题是:如何在不使用 objectForKey
的 PFObject
sp.name
尝试更改:
var name : String!
至:
@NSManaged public var name: String!