Question: Swift Loops 1. Declare an empty Array of integers 2. Initialize the array with even numbers between 1 and 100 3. Using for-loop print all
Swift Loops
1. Declare an empty Array of integers
2. Initialize the array with even numbers between 1 and 100
3. Using for-loop print all numbers along with the sum of digits
4. Using a repeat while loop add 3 to each number
5. Declare a string and cast it to an array of characters. Iterate over this array to print out the characters along with their indices
Swift Dictionary and Tuples
1. Create an array of dictionaries in which each dictionary in the array contains the keys firstName and lastName. Create an array with a name of your choosing that contains only the values for firstName in each dictionary.
2. Using the array of dictionaries created previously, this time create an array that contains the values for firstName and lastName in each dictionary separated by a delimiter of your choice.
3. Create a datatype called MyTuple using the typealias feature of swift. It should be a tuple containing 2 Strings (String , String).
4. Declare and initialize a tuple with any values of your choice.
5. Print both values of the tuple individually in the console
Swift Guard
i) Write a simple if-else block to do so.
ii) Use the nil coalescing operatior.
If let name = txtname.text
{ If let address = txtaddress.text
{ sendToServer(name , address) }
else { print (No address provided) } }
else { print (No name provided) }
Rewrite this piece of code using 2 guard statements.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
