3
votes

For a day now I've been trying to get a piece of code working to help me handle find-and-create for CoreData in a nice way (from this article I found http://emplementation.blogspot.nl/2011/12/importing-data-into-core-data-while.html). I ended up working with code blocks which I've never done before.

Somehow I can't fix the following error which occurs because something is different in my typedef from what I try to define in my function. I think I understand it has something to do with the block being defined as __strong in the typedef but differently in my implementation file.

Error

Incompatible block pointer types initializing '_strong objectOperationBlock' (aka 'void (^_strong)(NSManagedObjectContext *_strong, NSDictionary *_strong, NSManagedObject *_strong)') with an expression of type 'void (^)(NSManagedObject *_strong, NSDictionary *_strong, NSManagedObject *_strong)'

MyViewController.h

typedef void (^objectOperationBlock)(NSManagedObjectContext *context,
                                 NSDictionary *hostObjectData,
                                 NSManagedObject *localManagedObject);

MyViewController.m

objectOperationBlock matchedBlock = ^(NSManagedObject *context, NSDictionary *hostObjectData, NSManagedObject *localManagedObject){
    NSLog(@"Dosomething");
};

In all my attempts I've found out that this could will build (but it's not using the typedef)

void (^matchedBlock)(NSManagedObject*, NSDictionary*, NSManagedObject*) = ^(NSManagedObject *context, NSDictionary *hostObjectData, NSManagedObject *localManagedObject){
    NSLog(@"Dosomething");
};

Thanks in advance for all your help!

1
Cannot repeat this issue. Could you elaborate? - Richard J. Ross III

1 Answers

2
votes

Did I miss that the typedef should read:

typedef void (^objectOperationBlock)(NSManagedObject *managedObject,
                                     NSDictionary *hostObjectData,
                                     NSManagedObject *localManagedObject);