Kayla, this task should be treated as a fallback when you don't have other tasks to perform. I hope it is exciting. It is a new adventure in code! This is a baptism of fire. Lots of new concepts, lots of new challenges.
Country is a type that holds data describing a real world Country in Procuret. It is a very simple type. Procuret API emits JSON objects of the form...
{
"country_id": 1,
"name": "Australia"
}
That is, Country is composed of a integer number ("country_id") and a string name ("name").
Your challenge is to write a Swift struct definition that allows us to work with Country data in Swift.
Take inspiration from two places:
country.js - The JavaScript library implementation of Country
region.swift - The Swift library implementation of another simple data structure, Region.
You may also enjoy comparing the JavaScript Region and Swift Region implementations. Each is doing the same thing as the other, but using JavaScript or Swift syntax, and different standard libraries (that is, collections of code available to our library. For example, the CodingKeys protocol).
I suggest reading this article: Encoding and Decoding Custom Types. One of the great joys of working in Swift is that there are standardised, documented, well thought-out ways of doing things implemented by very smart people. Have a read of this article and see if it helps you understand any of the concepts you see in the Region struct, and your own Country struct.
sorry about the multi-commit. file didn't change much. I forgot to hit a button in Xcode so I did another commit just to make sure changes showed up here.
Objective: Add
Country
struct to the library.Kayla, this task should be treated as a fallback when you don't have other tasks to perform. I hope it is exciting. It is a new adventure in code! This is a baptism of fire. Lots of new concepts, lots of new challenges.
Country
is a type that holds data describing a real world Country in Procuret. It is a very simple type. Procuret API emits JSON objects of the form...That is,
Country
is composed of a integer number ("country_id"
) and a string name ("name"
).Your challenge is to write a Swift
struct
definition that allows us to work with Country data in Swift.Take inspiration from two places:
Region
.You may also enjoy comparing the JavaScript
Region
and SwiftRegion
implementations. Each is doing the same thing as the other, but using JavaScript or Swift syntax, and different standard libraries (that is, collections of code available to our library. For example, theCodingKeys
protocol).I suggest reading this article: Encoding and Decoding Custom Types. One of the great joys of working in Swift is that there are standardised, documented, well thought-out ways of doing things implemented by very smart people. Have a read of this article and see if it helps you understand any of the concepts you see in the
Region
struct, and your ownCountry
struct.Ask any and all questions!