Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a variable to hold data to pass.
iOS Swift
var message[1] String? Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' when declaring a variable type.
Using '!' or '?' incorrectly here.
✗ Incorrect
In Swift, to declare a variable with a type, use a colon : after the variable name.
2fill in blank
mediumComplete the code to override the prepare method for passing data.
iOS Swift
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "showDetail" { let destination = segue.[1] as! DetailViewController } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong property name like 'destinationVC' or 'destinationView'.
Forgetting to cast to the correct controller type.
✗ Incorrect
The correct property to get the destination view controller from a segue is destination.
3fill in blank
hardFix the error in passing data to the destination view controller.
iOS Swift
destination.message = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes which assign a string literal instead of the variable value.
Calling the variable like a function with parentheses.
✗ Incorrect
You assign the variable message directly without self. or parentheses.
4fill in blank
hardFill both blanks to safely unwrap and pass data in prepare method.
iOS Swift
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let destination = segue.[1] as? DetailViewController, let data = [2] { destination.message = data } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sender' instead of the data variable.
Using forced cast instead of optional cast.
✗ Incorrect
Use destination to get the destination safely and unwrap the message variable.
5fill in blank
hardFill all three blanks to create a dictionary and pass filtered data to destination.
iOS Swift
let filteredData = data.filter { $0.[1] [2] [3] }
destination.filteredItems = filteredData Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'length' which is not a Swift property.
Using '<' instead of '>' causing wrong filtering.
✗ Incorrect
Use count to get the length of each item, filter those with count greater than 5.