I finally was able to pull an array of images from Parse.com after fiddling with tutorials.
From that array I want to throw it on an image view via next random image with a swipe gesture:
var query = PFQuery(className:"cats")
query.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
for object in objects! {
// Update - replaced as with as!
self.imageFiles.append(object as! PFObject)
println(self.imageFiles)
self.view.addGestureRecognizer(rightSwipe)
}
} else {
// Log details of the failure
println(error)
}
}
}
The println(self.imageFiles)
actually shows the array of files which is great, what I'm having issues with is using the random generator.
Still new to syntax, I was trying to do like imageview.image = imageFiles[0]
or something like that to just display one of the images in the array. Not really sure the syntax though.
I'm guessing once I get that it would be imageview.image = imageFiles[RandomNumber]
or the equivalent.
for the swipe part I think I got that under control
Edit
ok I have:
let randomNumber = imageFiles[Int(arc4random_uniform(UInt32(imageFiles.count)))]
println(randomNumber)
and the println gives me a random image file from the array.
How do I put that into the image view?
EDIT just tried:
for randomNumber in imageFiles {
self.ImageView.image = randomNumber
}
and got:
cannot assign a value type pfobject to a value type of uiimage
self.ImageView.image = UIImage(data: randomNumber)
also gives me an error can't have data: PFObject