【发布时间】:2015-09-11 05:42:49
【问题描述】:
我正在尝试从objects 中提取prayerRequest。但是,我不完全确定如何做到这一点。
var allPrayerRequests = [""]
override func viewDidLoad() {
super.viewDidLoad()
var query = PFQuery(className: "PrayerRequests")
query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
println(object)
}
}
}
})
}
如果我这样做了,println(object),我会得到以下输出:
<PrayerRequests: 0x7feec8eec7f0, objectId: jy2KwGXenC, localId: (null)> {
ACL = "<PFACL: 0x7feec8eca220>";
prayerRequest = qoiejr;
}
<PrayerRequests: 0x7feec8eed9a0, objectId: KxMpxyWV0P, localId: (null)> {
ACL = "<PFACL: 0x7feec8eed600>";
prayerRequest = qwer;
}
<PrayerRequests: 0x7feec8eee5f0, objectId: DRHBwJpq16, localId: (null)> {
ACL = "<PFACL: 0x7feec8eee840>";
prayerRequest = zxcv;
}
<PrayerRequests: 0x7feec8eeecd0, objectId: cOOdOyv4TM, localId: (null)> {
ACL = "<PFACL: 0x7feec8eeef10>";
prayerRequest = oijg;
}
<PrayerRequests: 0x7feec8eef3c0, objectId: bmO3oVKUDG, localId: (null)> {
ACL = "<PFACL: 0x7feec8eef680>";
prayerRequest = asdf;
}
<PrayerRequests: 0x7feec8eef800, objectId: RcR3wbbMYv, localId: (null)> {
ACL = "<PFACL: 0x7feec8eefda0>";
prayerRequest = qwer;
}
所以,正如您在代码中看到的,有一个带有prayerRequest 的字段。我希望能够提取这个字段,就像我要执行 println(object.objectId) 一样,它将以下内容输出到控制台:
Optional("jy2KwGXenC")
Optional("KxMpxyWV0P")
Optional("DRHBwJpq16")
Optional("cOOdOyv4TM")
Optional("bmO3oVKUDG")
Optional("RcR3wbbMYv")
但只有 prayerRequest 字段。有人有办法做到这一点吗?
【问题讨论】:
-
试试这个 object.objectForKey("prayerRequest")
-
是的!有效。天啊。非常感谢!
标签: ios xcode swift parse-platform