Search code examples
swiftcore-dataobjective-c-blocksmagicalrecord

Swift syntax for MagicalRecord saveWithBlock


In objC the way to saveWithBlock is

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
        // This block runs in background thread
        } completion:^(BOOL success, NSError *error) {
        // This block runs in main thread
        }];

For the life of me, I cannot get the right Swift block/closure syntax correct. Don't know why this isn't sinking in with me. Could someone lend a hand and produce the swift version of above?


Solution

  • It should look something like this: off the top of my head...

    MagicalRecord.saveWithBlock({ (localContext : NSManagedObjectContext!) in
            // This block runs in background thread
        }, completion: { (success : Bool, error : NSError!) in
           // This block runs in main thread
        })