0
0
Swiftprogramming~10 mins

Type aliases for readability in 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 create a type alias named Age for Int.

Swift
typealias [1] = Int
Drag options to blanks, or click blank then click option'
ANumber
BAge
CInteger
DYears
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.
2fill in blank
medium

Complete 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'
APoint
BLocation
CCoordinates
DPosition
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.
3fill in blank
hard

Fix 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'
AIntPredicate
BCheckNumber
CNumberCheck
DBoolClosure
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.
4fill in blank
hard

Fill 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'
AJSONDictionary
BString
CInt
DAnyObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int as dictionary keys instead of String.
Using AnyObject instead of Any for values.
5fill in blank
hard

Fill 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'
ACompletionHandler
BBool
CString?
DVoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-optional String instead of optional.
Incorrect order of parameters in the closure.