Search code examples
iosxcodeswiftmagicalrecord

MagicalRecord saveWithBlock usage now fails to compile under XCode 7 beta 5


I just updated to beta 5 of XCode 7 and am now getting a compliation error on the following Swift code:

MagicalRecord.saveWithBlock({ (localContext : NSManagedObjectContext!) in
    // ... Save models here ...
    }, completion: { (success : Bool, error : NSError!) in
    // ... Handle completion here ...
})

Under previous builds of XCode 7, this compiled fine, but I'm now getting:

Cannot invoke 'saveWithBlock' with an argument list of type '((NSManagedObjectContext!) -> (), completion: (Bool, NSError!) -> ())'

I've tried adding -> Void (as autocompleted when I try to add the call afresh) and -> Void! to the parameters, but see the same error.

Is this a language change or a bug in this XCode build?

EDIT (5.42pm ETC 08/08/2015): Calling savedWithBlock without the completion handler appears to compile ok:

MagicalRecord.saveWithBlock { (localContext: NSManagedObjectContext!) -> Void in
   // ... Save models here ...
}

EDIT (8.32am ETC 08/11/2015): Following recommendation by @Gerd Castan, I also tried changing the completion parameter to:

completion: { (success : Bool, error : ErrorType!)

and

completion: { (success : ObjCBool, error : ErrorType!)

Both of which gave the same error.


Solution

  • This appears to be fixed with XCode 7 Beta 6. The syntax:

    MagicalRecord.saveWithBlock({ (localContext: NSManagedObjectContext!) -> Void in
        // Save model here
    }) { (success: Bool, error: NSError!) -> Void in
        // Handle result here
    }
    

    Compiles without error.