Question
Swift Collections: Write and test the code in Swift that meets the following requirements. States in the USA are abbreviated with two letter codes. For
Swift Collections: Write and test the code in Swift that meets the following requirements.
States in the USA are abbreviated with two letter codes. For example, Missouri is MO, Pennsylvania is PA, and California is CA.
Declare a variable called states that is declared as a Swift collection type that has elements that have keys which are a state's abbreviation and values that are a state's name. On the declaration line initialize the collection with an empty instance of the collection type.
Add Missouri (MO), Pennsylvania (PA), and California (CA) to the collection.
Using for-in iterate through the key/value pairs of the collection and print them in the format:
Obtain an array of all of the state abbreviations in the collection and assign it to a constant called stateCodes.
Iterate through the array of state abbreviations and print each one.
Remove Pennsylvania (PA) from the collection using subscript syntax and assigning a nil.
Remove Missouri (MO) from the collection using the removeValue(forKey:) method on the collection.
Using for-in iterate through the key/value pairs of the collection and print them in the format:
The output of your program should look like the following:
PA is Pennsylvania CA is California MO is Missouri PA CA MO CA is California
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started