I have declared a global variable 'var recipes = String: PFFile'. On parse.com, I created a column called "recipe" of type File and i have uploaded .txt files that contain the recipes. I am trying to load the contents of the .txt files from parse to a UITextView. I have tried many things and this is what I have:
var recipes = [String: PFFile]()
var valueToPass: String!
var valuePassed: String!
var appetizer = [String]()
var images = [String: UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
let query = PFQuery(className: "Appetizers")
query.orderByAscending("recipe")
query.findObjectsInBackgroundWithBlock { (objects, error) in
guard error == nil, let objects = objects else {
print(error)
return
}
for object in objects {
// ... Appetizer Name
let appetizerName = object.objectForKey("appetizer") as! String
self.name.text = self.valuePassed
// ... Recipe
var recipes = [String: String]()
let recipeFile = object["recipe"] as! PFFile
do {
let recipeData = try recipeFile.getData()
let recipe = String(data: recipeData , encoding:NSUTF8StringEncoding)!
print(recipe) // recipe is now a string you can store or display
self.myTextView.text = recipe
} catch {
print("something went wrong")
}
// ... Image
let imageFile = object["imageFiles"] as!PFFile
imageFile.getDataInBackgroundWithBlock({ (imageData, error) -> Void in
if error == nil {
let data = imageData
} else {
print(error)
}
if let data = imageData {
self.images[appetizerName] = UIImage(data: data)
self.imageView.image = self.images[self.valuePassed]
}
})
}
}
}
I am able to display the recipe with the above code but not the one i chose. It is printing all the recipes in the logs but in a random order (but the same order each time) and the last one is the one being printed in the UITextView.
I can't seem to get the one i am choosing.
object?