作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用解析来上传和检索图像。我正在使用以下代码上传图像。
@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/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!