w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Calling Objective c method in swift app

To use an Objective C Method in swift, you need to treat the method like a Swift function. You call functions on an instance through .

For you, it would be like this:

let request = _user.login
request.sendWithLoadMessage("Signing In", successMessage: "Signed In",
failureMessage: "Failed to log in", recoveryOptions: "try again", response:
{ CustomResponse in
    println(response) 
})

Taking advantage of trailing closures here:

let request = _user.login
request.sendWithLoadMessage("Signing In", successMessage: "Signed In",
failureMessage: "Failed to log in", recoveryOptions: "try again") {
response: CustomResponse in
    println(response) 
}

Using the $ syntax, you can make this even shorter by doing it this way. If you already know the parameters passed back in the block, you can access the list of parameters without typing it out by calling $indexOfParameter. The $ syntax is 0 indexed so your first parameter would be $0, your second parameter would be $1, etc.

let request = _user.login
request.sendWithLoadMessage("Signing In", successMessage: "Signed In",
failureMessage: "Failed to log in", recoveryOptions: "try again") {
    println($0) 
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.