我正在通过for循环查询进入名为“users”的数组的parse中的一些值。一旦值在数组中,我想在数组索引中提取单个值和部分。但是,我在做这件事时遇到了麻烦。这是我的代码:
var query = PFQuery(className:"UserData")
query.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]!, error: NSError!) -> Void in
self.users.removeAll(keepCapacity: true)
for object in objectss {
var topUsers:PFObject = object as PFObject
self.users.append("\(object)")
}
println(self.users[2])
我得到的输出是:
<UserData: 0x7fa5a848f570, objectId: RlvK3GhfqE, localId: (null)> {
hot = 59;
imageNumber = 1;
not = 17;
totalVotes = 104;
}
<UserData: 0x7fa5a85cfdc0, objectId: 30WlVtgurP, localId: (null)> {
hot = 13;
imageNumber = 2;
not = 24;
totalVotes = 37;
}
<UserData: 0x7fa5a85d02f0, objectId: 5D6ARjk3xS, localId: (null)> {
hot = 7;
imageNumber = 3;
not = 23;
totalVotes = 31;
}
<UserData: 0x7fa5a85d02f0, objectId: 5D6ARjk3xS, localId: (null)> {
hot = 7;
imageNumber = 3;
not = 23;
totalVotes = 31;
}
我如何提取:“热”及其自身的数值?或“不”或“totalVotes”?
提前多多感谢!
答案 0 :(得分:0)
获取属性,但引用它的名称。你应该检查数组长度和空值,但一般来说:
self.users[2]["hot"]
此外,在您的find块中,您应该能够直接设置users
数组,而无需遍历所有对象。
self.users = objects