3

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
  • 1
    Cannot repeat this issue. Could you elaborate? Commented Jun 7, 2012 at 13:26

1 Answer 1

2

Did I miss that the typedef should read:

typedef void (^objectOperationBlock)(NSManagedObject *managedObject,
                                     NSDictionary *hostObjectData,
                                     NSManagedObject *localManagedObject);
Sign up to request clarification or add additional context in comments.

3 Comments

Or, conversely, that the context variable in the assignment should be NSManagedObjectContext.
You are very right, no wonder it didn't work.. Thanks a lot, I need to get myself some fresh air!
Easy miss - I've been staring at 10 year old Makefiles all morning (don't ask!), just spotted omission.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.