I have this function, but when I run:
theRecipes.append(theRecipe);
...the size of the array 'theRecipes' is exactly the same. I share you the code so you can overview what I'm trying to do on Swift Language.
func retrieveAll() -> [Recipe] {
var query = PFQuery(className: RECIPE_PARSE_CLASSNAME);
var theRecipes: [Recipe] = [Recipe]();
query.findObjectsInBackgroundWithBlock {(objects: [AnyObject]!, error: NSError!) -> Void in
if (error == nil) {
// The find succeeded.
println("Successfully retrieved \(objects.count) recipes.");
// Do something with the found objects
if let recipes = objects as? [PFObject] {
for recipe in recipes {
let theRecipe: Recipe = Recipe();
theRecipe.name = recipe[RECIPE_PARSE_NAME_NAME] as String;
theRecipe.about = recipe[RECIPE_PARSE_ABOUT_NAME] as String;
theRecipe.cover = recipe[RECIPE_PARSE_COVER_NAME] as String;
theRecipe.preview = recipe[RECIPE_PARSE_PREVIEW_NAME] as String;
println(theRecipe.name);
theRecipes.append(theRecipe);
}
}
} else {
// Log details of the failure
println("Error: \(error) \(error.userInfo!)");
Bugsnag.notify(nil, withData: ["data": error.description]);
}
};
return theRecipes;
}
What I'm trying to do is collect every PFObject to translate it to my own Model class and for managing it that way while in memory. So I translate it and append it to the array to deliver it fulfilled with recipes.
I want to make clear that I already checked that I'm successfully retrieving every object from Parse and they're not null.
fetchInBackground" questions are becoming as prevalent as Java string comparison with==questions?