Course Hero Logo

The returned data of the above api is in json format

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 74 - 79 out of 940 pages.

The returned data of the above API is in JSON format. Here is a sample result:74Intermediate iOS 13 Programming with Swift by AppCoda
loans: ({activity = Retail;"basket_amount" = 0;"bonus_credit_eligibility" = 0;"borrower_count" = 1;description ={languages =(fr,en);};"funded_amount" = 0;id = 734117;image ={id = 1641389;"template_id" = 1;};"lender_count" = 0;"loan_amount" = 750;location ={country = Senegal;"country_code" = SN;geo ={level = country;pairs = "14 -14";type = point;};};name = "Mar\U00e8me";"partner_id" = 108;"planned_expiration_date" = "2016-08-05T09:20:02Z";"posted_date" = "2016-07-06T09:20:02Z";sector = Retail;status = fundraising;use = "to buy fabric to resell";},........)75Intermediate iOS 13 Programming with Swift by AppCoda
You will learn how to use theNSJSONSerializationclass to convert the JSON formatteddata into objects. It's unbelievably simple. You'll see what I mean in a while.To keep you focused on learning the JSON implementation, you can first download theproject template from. Ihave already created the skeleton of the app for you. It is a simple table-based app thatdisplays a list of loans provided by Kiva.org. The project template includes a pre-builtstoryboard and custom classes for the table view controller and prototype cell. If you runthe template, it should result in an empty table app.Figure 4.1. Kiva Loan Project Template - StoryboardCreating JSON Data ModelWe will first create a class to model a loan. It's not required for loading JSON but the bestpractice is to create a separate class (or structure) for storing the data model. TheLoanclass represents the loan information in the KivaLoan app and is used to store the loaninformation returned by Kiva.org. To keep things simple, we won't use all the returneddata of a loan. Instead, the app will just display the following fields of a loan:Name of the loan applicant76Intermediate iOS 13 Programming with Swift by AppCoda
name ="Mar\U00e8me";Country of the loan applicantlocation ={country = Senegal;"country_code"= SN;geo ={level = country;pairs ="14 -14";type = point;};};How the loan will be useduse ="to buy fabric to resell";Amount"loan_amount"=750;These fields are good enough for filling up the labels in the table view. Now create a newclass file using the Swift File template. Name itLoan.swiftand declare theLoanstructure like this:structLoan{varname: String =""varcountry: String =""varuse: String =""varamount: Int =0}77Intermediate iOS 13 Programming with Swift by AppCoda
JSON supports a few basic data types including number, String, Boolean, Array, andObjects (an associated array with key and value pairs).For the loan fields, the loan amount is stored as a numeric value in the JSON-formatteddata. This is why we declared theamountproperty with the typeInt. For the rest of thefields, they are declared with the typeString.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 940 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Winter
Professor
James
Tags
Bankruptcy in the United States

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture