0
0
Swiftprogramming~10 mins

Why Swift for Apple and beyond - Test Your Understanding

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

Complete the code to print a welcome message in Swift.

Swift
print([1])
Drag options to blanks, or click blank then click option'
AHello, Swift!
Bprintln("Hello, Swift!")
Cprint("Hello, Swift!")
D"Hello, Swift!"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the quotes around the text.
Trying to print without quotes causes an error.
2fill in blank
medium

Complete the code to declare a constant named 'platform' with value 'Apple'.

Swift
let [1] = "Apple"
Drag options to blanks, or click blank then click option'
Aplatform
BPlatform
Capple
Ddevice
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'Platform' instead of lowercase.
Using a different variable name.
3fill in blank
hard

Fix the error in the function that returns a greeting message.

Swift
func greet() -> String {
    return [1]
}
Drag options to blanks, or click blank then click option'
A"Hello Swift"
BHello Swift
Cprint("Hello Swift")
Dreturn "Hello Swift"
Attempts:
3 left
💡 Hint
Common Mistakes
Returning text without quotes causes an error.
Using print inside return is incorrect.
4fill in blank
hard

Fill both blanks to create a dictionary of Apple platforms and their release years.

Swift
let platforms = ["iOS": [1], "macOS": [2]]
Drag options to blanks, or click blank then click option'
A2007
B2001
C2010
D1999
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the years for iOS and macOS.
Using years not related to Apple platforms.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary of platforms released after 2005.

Swift
let recentPlatforms = Dictionary(uniqueKeysWithValues: platforms.filter { ([1], [2]) in [3] > 2005 })
Drag options to blanks, or click blank then click option'
Aname
Byear
Cplatform
DreleaseYear
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that don't match like 'name' or 'releaseYear'.
Confusing keys and values, e.g., using 'platform' in the numeric condition.