Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a typealias named Age for Int.
Swift
typealias [1] = Int Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for typealias which is not a convention.
Trying to assign a value instead of a type.
✗ Incorrect
The keyword
typealias creates a new name for an existing type. Here, Age is the new name for Int.2fill in blank
mediumComplete the code to create a typealias named Coordinates for a tuple of two Double values.
Swift
typealias [1] = (Double, Double) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a name that does not clearly represent a pair of values.
Using a typealias name that is too generic.
✗ Incorrect
The typealias
Coordinates represents a tuple with two Double values, useful for x and y positions.3fill in blank
hardFix the error in the code by completing the typealias declaration for Text as String.
Swift
typealias [1] = String Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for typealias which causes style warnings.
Using all uppercase which is not conventional for type names.
✗ Incorrect
Typealias names should start with a capital letter by convention.
Text is the correct form.4fill in blank
hardFill both blanks to create a typealias named CompletionHandler for a closure that takes a Bool and returns Void.
Swift
typealias [1] = ([2]) -> Void
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter type in the closure.
Confusing the closure return type with the parameter type.
✗ Incorrect
The typealias
CompletionHandler represents a closure that takes a Bool parameter and returns nothing (Void).5fill in blank
hardFill all three blanks to create a typealias named JSONDictionary for a dictionary with String keys and Any values.
Swift
typealias [1] = [[2]: [3]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect types for keys or values.
Mixing up keys and values in the dictionary syntax.
✗ Incorrect
The typealias
JSONDictionary defines a dictionary with keys of type String and values of any type (Any), commonly used for JSON data.