gpt4 book ai didi

swift - 仅检索用户上传的图像

转载 作者:行者123 更新时间:2023-11-30 10:14:15 24 4
gpt4 key购买 nike

我正在使用解析来上传和检索图像。我正在使用以下代码上传图像。

  @IBAction func uploadButton(sender: AnyObject) {
var imageText = uploadMessage.text

if uploadPreviewImageView.image == nil {
//image is not included alert user
println("Image not uploaded")
}else {

var posts = PFObject(className: "Posts")
posts["imageText"] = imageText
posts["uploader"] = PFUser.currentUser()
posts.saveInBackgroundWithBlock({
(success: Bool, error: NSError?) -> Void in

if error == nil {

var imageData = UIImagePNGRepresentation(self.uploadPreviewImageView.image)
var parseImageFile = PFFile(name: "uploaded_image.png", data: imageData)
posts["imageFile"] = parseImageFile
posts.saveInBackgroundWithBlock({
(success: Bool, error: NSError?) -> Void in

if error == nil {

正如问题标题所述,我只想检索用户拍摄的图像。

var query = PFQuery(className: "Tops")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock{
(posts: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
for post in posts!{
self.imageFiles.append(post["imageFile"]as! PFFile)
self.imageText.append(post["imageText"]as! String)
}


println(self.imageFiles.count)
self.topsTableView.reloadData()

} else {
println(error)
}}}

在上面的代码中,我可以检索图像,但是如果我注销并登录到另一个帐户,我就可以看到其他用户上传的图像。这怎么可能?我无法找到执行此操作的教程和文档。谢谢

最佳答案

您基本上需要为查询定义一个谓词。 Parse 支持 NSPredicate 和它们自己的类似谓词的机制。

出于您的目的,您应该将查询条件设置为仅用户拍摄的照片。可以表示为 query.whereKey("uploader", equalTo: PFUser.currentUser())

用简单的英语来说,这就像说 - 嘿查询,返回我的结果,其中上传者属性具有我当前用户的值。

您在上传时已设置此属性:]

关于swift - 仅检索用户上传的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31136319/

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