0
0
iOS Swiftmobile~10 mins

Passing data to destination in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A?
B:
C=
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' when declaring a variable type.
Using '!' or '?' incorrectly here.
2fill in blank
medium

Complete 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'
Adestination
BdestinationVC
CdestinationViewController
DdestinationView
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong property name like 'destinationVC' or 'destinationView'.
Forgetting to cast to the correct controller type.
3fill in blank
hard

Fix 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'
Aself.message
Bself.message()
C"message"
Dmessage
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.
4fill in blank
hard

Fill 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'
AdestinationViewController
Bself.message
Cmessage
Dsender
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sender' instead of the data variable.
Using forced cast instead of optional cast.
5fill in blank
hard

Fill 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'
Acount
B>
C5
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'length' which is not a Swift property.
Using '<' instead of '>' causing wrong filtering.