How to access JSON response in Swift using AWS API Gateway-generated iOS SDKHow do I call Objective-C code from Swift?Amazon API Gateway IAM authenticated example with generated JS SDKEvaluate requests in the API Gateway“unsupported URL” error given when accessing api gateway endpoint from swiftTrying to make a “Hello World” AWS API Gateway GET API call from Android using Generated SDKAWS API Gateway Error Handling with Generated SDK (Swift)Issue in invoking AWS Lambda function with API GatewayiOS SDK generated by AWS API Gateway is missing required 'defaultClient' memberHow do I see contents of this Swift class object in Xcode after breakpoint?What is the proper way to work with API Gateway AWSTask objects in Swift

Should a TA point out a professor's mistake while attending their lecture?

What do the different role icons backgrounds mean?

Why does Sauron not permit his followers to use his name?

Small RAM 4 KB on the early Apple II?

Is "prohibition against," a double negative?

Does the telecom provider need physical access to the SIM card to clone it?

In what language did Túrin converse with Mím?

Is Borg adaptation only temporary?

How can I portray a character with no fear of death, without them sounding utterly bored?

Connecting points from separate Tikz figures

Printing a list as "a, b, c." using Python

How to animate a function plot

Can I leave a large suitcase at TPE during a 4-hour layover, and pick it up 4.5 days later when I come back to TPE on my way to Taipei downtown?

In Endgame, wouldn't Stark have remembered Hulk busting out of the stairwell?

What is this "opened" cube called?

Welche normative Autorität hat der Duden? / What's the normative authority of the Duden?

What is the following VRP?

Stock Volatility with Uncertain Probability

Coupling two 15 Amp circuit breaker for 20 Amp

Why haven't the British protested Brexit as ardently like Hong Kongers protest?

Why do motor drives have multiple bus capacitors of small value capacitance instead of a single bus capacitor of large value?

Why don't 3D printer heads use ceramic inner walls?

My colleague treats me like he's my boss, yet we're on the same level

How to prevent graphics clipping through each other



How to access JSON response in Swift using AWS API Gateway-generated iOS SDK


How do I call Objective-C code from Swift?Amazon API Gateway IAM authenticated example with generated JS SDKEvaluate requests in the API Gateway“unsupported URL” error given when accessing api gateway endpoint from swiftTrying to make a “Hello World” AWS API Gateway GET API call from Android using Generated SDKAWS API Gateway Error Handling with Generated SDK (Swift)Issue in invoking AWS Lambda function with API GatewayiOS SDK generated by AWS API Gateway is missing required 'defaultClient' memberHow do I see contents of this Swift class object in Xcode after breakpoint?What is the proper way to work with API Gateway AWSTask objects in Swift






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a working REST API based on this API Gateway tutorial. I'm able to successfully invoke it via the test functionality of the AWS Console; and I'm able to successfully invoke it via my simple iOS Swift 4.2 Xcode application using the iPhone XR simulator.



I know it's working via a real, live external call because I can see the Cloudwatch logs which always register a 200 response and is sending the results back to the Client.



My problem is really in understanding the Swift code, and I'm hoping that a Swift expert can help me understand how to unpack result in the code below.



Here's my code in ViewController.swift for invoking the REST API and attempting to print result to the console:



@IBAction func userInvokeApi(_ sender: UIButton) 
print("You clicked invoke api...")
let client = SVTLambdaGateClient.default()
client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith (task: AWSTask?) -> AnyObject? in
if let error = task?.error
print("Error occurred: (error)")
return nil


if let result = task?.result
// Do something with result
print("The result is... (result)")


return nil




As pointed out in the comments below, I'm getting the following result because it's printing out the address of the object:



You clicked invoke api...
The result is... <AmplifyRestApiTest.Empty: 0x600002020770>



(where AmplifyRestApiTest is the name of my Xcode project.)



UPDATE When I set a breakpoint on the print statement, this is what I see in the Debug pane:



Screenshot of debug pane showing trace at breakpoint at print statement.



UPDATE 2
When I type task?.result there are two viable properties as per this answer from the Amplify team: error and result. So, since my API responds successfully I am assuming I just don't know how to view result.



Can someone help me understand what steps I must take to access members of this class object?



Here is the corresponding method in the API Gateway-generated iOS Swift SDK code:



/*
@param operand2
@param _operator
@param operand1

return type: Empty
*/
public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty>
let headerParameters = [
"Content-Type": "application/json",
"Accept": "application/json",

]

var queryParameters:[String:Any] = [:]
queryParameters["operand2"] = operand2
queryParameters["operator"] = _operator
queryParameters["operand1"] = operand1

let pathParameters:[String:Any] = [:]

return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>



I'm fairly certain this return type of Empty refers to the Empty model defined for the REST API as shown in the screenshot below. I think it's "empty" because the API doesn't alter the response from the Lambda function back to the Client. So, it's all pass-through. Indeed, the tutorial explains that the other models -- Output and Result -- are not used because it "relies on the passthrough behavior and does not use this model."



Any thoughts?



API Gateway screenshot showing Empty model










share|improve this question


























  • You could try print(String(bytes: result, encoding: .utf8)!)

    – Don
    Mar 27 at 23:47











  • Thanks Don. Unfortunately, when I use that construct I get the following error message: Argument type 'Empty' does not conform to expected type 'Sequence'. Which I don't really understand..

    – motivus
    Mar 28 at 0:11












  • have you tried if let result = task?.result // Do something with result print("The result is... (result.anyProprty from Empty class?)")

    – Abu Ul Hassan
    Mar 28 at 13:26






  • 1





    you are actually printing a class object which always prints address for object when you print something like print(result.title) you may find a value

    – Abu Ul Hassan
    Mar 28 at 13:27







  • 1





    by pressing escape button it shows possible properties and functions you can use with that object sorry for late i was just taking some off days.

    – Abu Ul Hassan
    Apr 8 at 5:40

















0















I have a working REST API based on this API Gateway tutorial. I'm able to successfully invoke it via the test functionality of the AWS Console; and I'm able to successfully invoke it via my simple iOS Swift 4.2 Xcode application using the iPhone XR simulator.



I know it's working via a real, live external call because I can see the Cloudwatch logs which always register a 200 response and is sending the results back to the Client.



My problem is really in understanding the Swift code, and I'm hoping that a Swift expert can help me understand how to unpack result in the code below.



Here's my code in ViewController.swift for invoking the REST API and attempting to print result to the console:



@IBAction func userInvokeApi(_ sender: UIButton) 
print("You clicked invoke api...")
let client = SVTLambdaGateClient.default()
client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith (task: AWSTask?) -> AnyObject? in
if let error = task?.error
print("Error occurred: (error)")
return nil


if let result = task?.result
// Do something with result
print("The result is... (result)")


return nil




As pointed out in the comments below, I'm getting the following result because it's printing out the address of the object:



You clicked invoke api...
The result is... <AmplifyRestApiTest.Empty: 0x600002020770>



(where AmplifyRestApiTest is the name of my Xcode project.)



UPDATE When I set a breakpoint on the print statement, this is what I see in the Debug pane:



Screenshot of debug pane showing trace at breakpoint at print statement.



UPDATE 2
When I type task?.result there are two viable properties as per this answer from the Amplify team: error and result. So, since my API responds successfully I am assuming I just don't know how to view result.



Can someone help me understand what steps I must take to access members of this class object?



Here is the corresponding method in the API Gateway-generated iOS Swift SDK code:



/*
@param operand2
@param _operator
@param operand1

return type: Empty
*/
public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty>
let headerParameters = [
"Content-Type": "application/json",
"Accept": "application/json",

]

var queryParameters:[String:Any] = [:]
queryParameters["operand2"] = operand2
queryParameters["operator"] = _operator
queryParameters["operand1"] = operand1

let pathParameters:[String:Any] = [:]

return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>



I'm fairly certain this return type of Empty refers to the Empty model defined for the REST API as shown in the screenshot below. I think it's "empty" because the API doesn't alter the response from the Lambda function back to the Client. So, it's all pass-through. Indeed, the tutorial explains that the other models -- Output and Result -- are not used because it "relies on the passthrough behavior and does not use this model."



Any thoughts?



API Gateway screenshot showing Empty model










share|improve this question


























  • You could try print(String(bytes: result, encoding: .utf8)!)

    – Don
    Mar 27 at 23:47











  • Thanks Don. Unfortunately, when I use that construct I get the following error message: Argument type 'Empty' does not conform to expected type 'Sequence'. Which I don't really understand..

    – motivus
    Mar 28 at 0:11












  • have you tried if let result = task?.result // Do something with result print("The result is... (result.anyProprty from Empty class?)")

    – Abu Ul Hassan
    Mar 28 at 13:26






  • 1





    you are actually printing a class object which always prints address for object when you print something like print(result.title) you may find a value

    – Abu Ul Hassan
    Mar 28 at 13:27







  • 1





    by pressing escape button it shows possible properties and functions you can use with that object sorry for late i was just taking some off days.

    – Abu Ul Hassan
    Apr 8 at 5:40













0












0








0


1






I have a working REST API based on this API Gateway tutorial. I'm able to successfully invoke it via the test functionality of the AWS Console; and I'm able to successfully invoke it via my simple iOS Swift 4.2 Xcode application using the iPhone XR simulator.



I know it's working via a real, live external call because I can see the Cloudwatch logs which always register a 200 response and is sending the results back to the Client.



My problem is really in understanding the Swift code, and I'm hoping that a Swift expert can help me understand how to unpack result in the code below.



Here's my code in ViewController.swift for invoking the REST API and attempting to print result to the console:



@IBAction func userInvokeApi(_ sender: UIButton) 
print("You clicked invoke api...")
let client = SVTLambdaGateClient.default()
client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith (task: AWSTask?) -> AnyObject? in
if let error = task?.error
print("Error occurred: (error)")
return nil


if let result = task?.result
// Do something with result
print("The result is... (result)")


return nil




As pointed out in the comments below, I'm getting the following result because it's printing out the address of the object:



You clicked invoke api...
The result is... <AmplifyRestApiTest.Empty: 0x600002020770>



(where AmplifyRestApiTest is the name of my Xcode project.)



UPDATE When I set a breakpoint on the print statement, this is what I see in the Debug pane:



Screenshot of debug pane showing trace at breakpoint at print statement.



UPDATE 2
When I type task?.result there are two viable properties as per this answer from the Amplify team: error and result. So, since my API responds successfully I am assuming I just don't know how to view result.



Can someone help me understand what steps I must take to access members of this class object?



Here is the corresponding method in the API Gateway-generated iOS Swift SDK code:



/*
@param operand2
@param _operator
@param operand1

return type: Empty
*/
public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty>
let headerParameters = [
"Content-Type": "application/json",
"Accept": "application/json",

]

var queryParameters:[String:Any] = [:]
queryParameters["operand2"] = operand2
queryParameters["operator"] = _operator
queryParameters["operand1"] = operand1

let pathParameters:[String:Any] = [:]

return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>



I'm fairly certain this return type of Empty refers to the Empty model defined for the REST API as shown in the screenshot below. I think it's "empty" because the API doesn't alter the response from the Lambda function back to the Client. So, it's all pass-through. Indeed, the tutorial explains that the other models -- Output and Result -- are not used because it "relies on the passthrough behavior and does not use this model."



Any thoughts?



API Gateway screenshot showing Empty model










share|improve this question
















I have a working REST API based on this API Gateway tutorial. I'm able to successfully invoke it via the test functionality of the AWS Console; and I'm able to successfully invoke it via my simple iOS Swift 4.2 Xcode application using the iPhone XR simulator.



I know it's working via a real, live external call because I can see the Cloudwatch logs which always register a 200 response and is sending the results back to the Client.



My problem is really in understanding the Swift code, and I'm hoping that a Swift expert can help me understand how to unpack result in the code below.



Here's my code in ViewController.swift for invoking the REST API and attempting to print result to the console:



@IBAction func userInvokeApi(_ sender: UIButton) 
print("You clicked invoke api...")
let client = SVTLambdaGateClient.default()
client.calcGet(operand2: "3", _operator: "+", operand1: "5").continueWith (task: AWSTask?) -> AnyObject? in
if let error = task?.error
print("Error occurred: (error)")
return nil


if let result = task?.result
// Do something with result
print("The result is... (result)")


return nil




As pointed out in the comments below, I'm getting the following result because it's printing out the address of the object:



You clicked invoke api...
The result is... <AmplifyRestApiTest.Empty: 0x600002020770>



(where AmplifyRestApiTest is the name of my Xcode project.)



UPDATE When I set a breakpoint on the print statement, this is what I see in the Debug pane:



Screenshot of debug pane showing trace at breakpoint at print statement.



UPDATE 2
When I type task?.result there are two viable properties as per this answer from the Amplify team: error and result. So, since my API responds successfully I am assuming I just don't know how to view result.



Can someone help me understand what steps I must take to access members of this class object?



Here is the corresponding method in the API Gateway-generated iOS Swift SDK code:



/*
@param operand2
@param _operator
@param operand1

return type: Empty
*/
public func calcGet(operand2: String, _operator: String, operand1: String) -> AWSTask<Empty>
let headerParameters = [
"Content-Type": "application/json",
"Accept": "application/json",

]

var queryParameters:[String:Any] = [:]
queryParameters["operand2"] = operand2
queryParameters["operator"] = _operator
queryParameters["operand1"] = operand1

let pathParameters:[String:Any] = [:]

return self.invokeHTTPRequest("GET", urlString: "/calc", pathParameters: pathParameters, queryParameters: queryParameters, headerParameters: headerParameters, body: nil, responseClass: Empty.self) as! AWSTask<Empty>



I'm fairly certain this return type of Empty refers to the Empty model defined for the REST API as shown in the screenshot below. I think it's "empty" because the API doesn't alter the response from the Lambda function back to the Client. So, it's all pass-through. Indeed, the tutorial explains that the other models -- Output and Result -- are not used because it "relies on the passthrough behavior and does not use this model."



Any thoughts?



API Gateway screenshot showing Empty model







ios swift xcode amazon-web-services aws-api-gateway






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 10 at 15:56







motivus

















asked Mar 27 at 23:02









motivusmotivus

7310 bronze badges




7310 bronze badges















  • You could try print(String(bytes: result, encoding: .utf8)!)

    – Don
    Mar 27 at 23:47











  • Thanks Don. Unfortunately, when I use that construct I get the following error message: Argument type 'Empty' does not conform to expected type 'Sequence'. Which I don't really understand..

    – motivus
    Mar 28 at 0:11












  • have you tried if let result = task?.result // Do something with result print("The result is... (result.anyProprty from Empty class?)")

    – Abu Ul Hassan
    Mar 28 at 13:26






  • 1





    you are actually printing a class object which always prints address for object when you print something like print(result.title) you may find a value

    – Abu Ul Hassan
    Mar 28 at 13:27







  • 1





    by pressing escape button it shows possible properties and functions you can use with that object sorry for late i was just taking some off days.

    – Abu Ul Hassan
    Apr 8 at 5:40

















  • You could try print(String(bytes: result, encoding: .utf8)!)

    – Don
    Mar 27 at 23:47











  • Thanks Don. Unfortunately, when I use that construct I get the following error message: Argument type 'Empty' does not conform to expected type 'Sequence'. Which I don't really understand..

    – motivus
    Mar 28 at 0:11












  • have you tried if let result = task?.result // Do something with result print("The result is... (result.anyProprty from Empty class?)")

    – Abu Ul Hassan
    Mar 28 at 13:26






  • 1





    you are actually printing a class object which always prints address for object when you print something like print(result.title) you may find a value

    – Abu Ul Hassan
    Mar 28 at 13:27







  • 1





    by pressing escape button it shows possible properties and functions you can use with that object sorry for late i was just taking some off days.

    – Abu Ul Hassan
    Apr 8 at 5:40
















You could try print(String(bytes: result, encoding: .utf8)!)

– Don
Mar 27 at 23:47





You could try print(String(bytes: result, encoding: .utf8)!)

– Don
Mar 27 at 23:47













Thanks Don. Unfortunately, when I use that construct I get the following error message: Argument type 'Empty' does not conform to expected type 'Sequence'. Which I don't really understand..

– motivus
Mar 28 at 0:11






Thanks Don. Unfortunately, when I use that construct I get the following error message: Argument type 'Empty' does not conform to expected type 'Sequence'. Which I don't really understand..

– motivus
Mar 28 at 0:11














have you tried if let result = task?.result // Do something with result print("The result is... (result.anyProprty from Empty class?)")

– Abu Ul Hassan
Mar 28 at 13:26





have you tried if let result = task?.result // Do something with result print("The result is... (result.anyProprty from Empty class?)")

– Abu Ul Hassan
Mar 28 at 13:26




1




1





you are actually printing a class object which always prints address for object when you print something like print(result.title) you may find a value

– Abu Ul Hassan
Mar 28 at 13:27






you are actually printing a class object which always prints address for object when you print something like print(result.title) you may find a value

– Abu Ul Hassan
Mar 28 at 13:27





1




1





by pressing escape button it shows possible properties and functions you can use with that object sorry for late i was just taking some off days.

– Abu Ul Hassan
Apr 8 at 5:40





by pressing escape button it shows possible properties and functions you can use with that object sorry for late i was just taking some off days.

– Abu Ul Hassan
Apr 8 at 5:40












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387779%2fhow-to-access-json-response-in-swift-using-aws-api-gateway-generated-ios-sdk%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387779%2fhow-to-access-json-response-in-swift-using-aws-api-gateway-generated-ios-sdk%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현