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

1 Answer 1

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)")
    }
})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.