Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

From Parse to Core Data: After download complete, how to save image to device!

Hi,

I saved all my data to Parse.com (including vector images as pdf files).

I want to get all this data, save it to a managed object and than save the context. Because getting data in background is asynchronous, i have to wait for download to finish before saving it to core data stack.

I want to use a method for file download operations:

CoreDataStack *coreDataStack = [CoreDataStack defaultStack];
            CardData *cardData = [NSEntityDescription insertNewObjectForEntityForName:@"CardData" inManagedObjectContext:coreDataStack.managedObjectContext];
...
cardData.cardVisual = [self fileDataForStackFromParseFile: [dict objectForKey:@"cardVisual"]];
...
[coreDataStack saveContext];
...
-(NSData*) fileDataForStackFromParseFile:(NSData*)data {

    PFFile *userImageFile = [PFFile fileWithData:data];
    [userImageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (error) {
            NSLog(@"zzbamm! %@",error);
        } else {
            return userImageFile; //the data for saving to stack
        }
    }];
}

I get the error below, at the ^ block sign:

Incompatible block pointer types sending 'PFFile *(^)(NSData *strong, NSError *strong)' to parameter of type 'PFDataResultBlock' (aka 'void (^)(NSData *strong, NSError *strong)')

I think IOS assumes that i try to return something from a void method, in fact that return is for my "fileDataForStackFromParseFile" method.

What seems to be the problem?

I also want to ask if this is a good approach for my purpose or it is completely useless? Any other suggestions?

I'm stuck, your help needed.