Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a type alias 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 a name that is not descriptive of the type's purpose.
Trying to create an alias without the 'typealias' keyword.
✗ Incorrect
The keyword
typealias creates a new name for an existing type. Here, Age is the alias for Int.2fill in blank
mediumComplete the code to define a type alias 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
Using a name that does not imply a pair of values.
Forgetting to use parentheses for the tuple type.
✗ Incorrect
The alias
Coordinates clearly represents a tuple of two Double values, often used for x and y positions.3fill in blank
hardFix the error in the code by completing the type alias for a closure that takes an Int and returns a Bool.
Swift
typealias [1] = (Int) -> Bool Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a name that does not clearly indicate a boolean test.
Confusing the order of parameters and return type.
✗ Incorrect
The alias
IntPredicate is a common name for a closure that tests an Int and returns a Bool.4fill in blank
hardFill both blanks to create a type alias JSONDictionary for a dictionary with String keys and Any values.
Swift
typealias [1] = [[2]: Any]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
Int as dictionary keys instead of String.Using
AnyObject instead of Any for values.✗ Incorrect
The alias
JSONDictionary represents a dictionary with String keys and values of any type, useful for JSON data.5fill in blank
hardFill all three blanks to create a type alias CompletionHandler for a closure that takes a Bool, an optional String, and returns Void.
Swift
typealias [1] = ([2], [3]) -> Void
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-optional
String instead of optional.Incorrect order of parameters in the closure.
✗ Incorrect
The alias
CompletionHandler defines a closure taking a Bool and an optional String, returning nothing (Void).