问题描述
我有一个UIImage数组,图像,声明为
I have an UIImage array, images, which is declared as
var images = [UIImage]()
我目前在那里存储图片,当我使用println()函数输出图片时,我得到
I currently have pictures stored in there, and when I output it using the println() function, I get
[<UIImage: 0x195dc810>, <UIImage: 0x195da3e0>, <UIImage: 0x1950ab50>]
我想知道如何将这些图像作为一行上传到Parse.
I was wondering how I could upload these images to Parse as one row.
这是我现在拥有的全部代码(无效):
Here is my full code of what I have now(not working):
@IBAction func saveToParse(sender: AnyObject) {
for var i = 0; i < images.count; i++
{
var objectForSave:PFObject = PFObject(className: "NewLog")
//error on this line below: [(UIImage)] does not have a member variable named 'objectAtIndex'
let imageData:NSData = NSData(data: UIImagePNGRepresentation(images.objectAtIndex(i) as! UIImage))
var imageFile:PFFile = PFFile(data: imageData)
imageFile.saveInBackgroundWithBlock({ (success:Bool, error:NSError?) -> Void in
if success{
objectForSave.setObject(imageFile, forKey: "Image")
objectForSave.saveInBackgroundWithBlock({ (success:Bool, error:NSError?) -> Void in
if success{
//do smth
}else{
println(error)
}
})
}else{
println(error)
}
}, progressBlock: { (progress:Int32) -> Void in
})
}
}
谢谢.
推荐答案
您可以遍历数组中的所有项目,而无需遍历数组并使用索引.
Instead of iterating over the array and using the index, you can iterate over all the items in the array.
for image in images
这将获取数组中的每个图像. for循环中的所有内容将对数组中的每个项目执行一次.
This will get every single image in the array. Everything in the for loop will be executed once for every item in the array.
您将使用image
而不是images.objectAtIndex(i) as! UIImage
这还将使您的代码更易于他人阅读;)
This will also make your code easier to read for others ;)
这篇关于将图像从[UIImage]数组存储到Parse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!