wil
wil

Reputation: 903

insert using custom api with azure services using swift

I am new to Swift language. I am trying to use custom API to Azure service. I am not sure how to return the result back.

Here is my Swift code calling Azure mobile service:

client?.invokeAPI(APIName: "add", data: itemToInsert, HTTPMethod: "POST", parameters: nil, headers: nil, completion: "What do I insert here?" )

This is the what intellisense give but not sure how to handle the completion part.

client?.invokeAPI(APIName: String!, body: <#AnyObject!#>, HTTPMethod: <#String!#>, parameters: <#[NSObject : AnyObject]!#>, headers: <#[NSObject : AnyObject]!#>, completion: { (<#AnyObject!#>, <#NSHTTPURLResponse!#>, <#NSError!#>) -> Void in
    <#code#>
})

Upvotes: 1

Views: 687

Answers (1)

phillipv
phillipv

Reputation: 1717

There are 2 invoke API methods, and they both have slightly different completion blocks (I'm not sure which one you are trying to call)

One assumes you are working with JSON, while the other lets you control the data out & in via the API. Calling the JSON based one would look like so:

client.invokeAPI("add", body: jsonItem, HTTPMethod: "POST", parameters: nil, headers: nil) {
    myobject, response, error in

    println(myobject);
}

My object will be the response string parsed as JSON, so typically an NSDictionary. The others as shown in your question are a NSHTTPUrlResponse and a NSError object.

Upvotes: 2

Related Questions