1

I try to convert Objective-C block syntax to Swift Xcode 6.3.2

completion block typedef:

typealias CompletionWithBoolBlock = (Bool, NSError, NSString) -> Void

[Model insertObjectWithTable:@"tblStudent" values:dict completion:^(BOOL success, NSError *responseError, NSString *object){
        
        if(success){
            NSLog(@"inserted");
        }
        else
        {
             NSLog(@"Not inserted, %@",responseError.description);
        }
    }];

After surfing on net, I tried with

    Model.insertObjectWithTable("tblStudent", values: dict, completion:({(success:Bool,responseError:NSError, object:NSString)->(Void) in
        
        if success
            {
                println("inserted")
            }
            else
            {
                 println("Not inserted \(responseError.description)")
            }
        })
}

and

    Model.insertObjectWithTable("tblStudent", values: dict, completion:(success:Bool,responseError:NSError, object:NSString)->Void{
        
        if success
            {
                println("inserted")
            }
            else
            {
                 println("Not inserted \(responseError.description)")
            }
        })

but it shows me error

Expected ',' separator

Expected expression in list of expressions

Community
  • 1
  • 1
Soniya
  • 600
  • 7
  • 34

1 Answers1

2

Have you tried

Model.insertObjectWithTable("tblStudent", values: dict, completion:{(success:Bool, responseError:NSError, object:NSString) -> Void in
    if success {
        println("inserted")
    } else {
        println("Not inserted \(responseError.description)")
    }
})
luk2302
  • 55,258
  • 23
  • 97
  • 137