gpt4 book ai didi

ios - Parse.com 使用 Swift 获取 ObjectID

转载 作者:行者123 更新时间:2023-11-28 10:25:00 25 4
gpt4 key购买 nike

我目前从我的第一个解析步骤开始,但目前我停留在一个非常基本的点上。有什么方法可以从我的“parseObject”中取回一个包含我所有“objectID”列表的数组吗?

我只是想要一个数组,从一个“表”中获取所有自动设置的 objectID

最佳答案

这是一个 Swift 解决方案:

        // objectIds is your array to store the objectId values returned from parse
// objectId is a String

var objectIds:[""] // empty string array
func loadDataFromParse () {
var query = PFQuery(className:"Record")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
for object in objects {
objectIds.append(object.objectId as String)
}
} else {
println("\(error)")
}

}

}


// this function will retrieve a photo in the record with specified objectId
// and store it in noteImage

var noteImage = UIImage() // where retrieved image is stored
func loadImageFromParse (objectId: String) {

var query = PFQuery(className:"Record")
query.whereKey("objectId", equalTo:objectId)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
println("Successfully retrieved \(objects.count) records.")
for object in objects {
let userImageFile = object["image"] as PFFile!
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
noteImage = UIImage(data:imageData)!
println("Image successfully retrieved")
}
}
}

} else {
NSLog("Error: %@ %@", error, error.userInfo!)
}
}
}

关于ios - Parse.com 使用 Swift 获取 ObjectID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28365422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com