Question
Exercise - Type Casting and Inspection Note: Chosen Language is Swift Create a collection of type [Any], including a few doubles, integers, strings, and booleans
Exercise - Type Casting and Inspection
Note: Chosen Language is "Swift"
Create a collection of type [Any], including a few doubles, integers, strings, and booleans within the collection. Print the contents of the collection.
Loop through the collection. For each integer, print "The integer has a value of ", followed by the integer value. Repeat the steps for doubles, strings and booleans.
Create a [String : Any] dictionary, where the values are a mixture of doubles, integers, strings, and booleans. Print the key/value pairs within the collection
Create a variable total of type Double set to 0. Then loop through the dictionary, and add the value of each integer and double to your variable's value. For each string value, add 1 to the total. For each boolean, add 2 to the total if the boolean is true, or subtract 3 if it's false. Print the value of total.
Create a variable total2 of type Double set to 0. Loop through the collection again, adding up all the integers and doubles. For each string that you come across during the loop, attempt to convert the string into a number, and add that value to the total. Ignore booleans. Print the total.
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