About this exam
App-Development-with-Swift-Certified-User is the Apple exam App Development with Swift Certified User Exam.
Paid practice material for this exam is not available yet, but you can try its free sample questions.
- Exam code
- App-Development-with-Swift-Certified-User
- Vendor
- Apple
- Practice questions
- Not available yet
- Free sample questions
- 1
- Question bank last updated
- Not available yet
Try 1 sample question
Taken from the free sample set for App-Development-with-Swift-Certified-User.
Question 1 (choose 2)
Review the code.
var capitalCities = [ " USA " : " Washington D.C. " , " Spain " : " Madrid " , " Peru " : " Lima " ]
Which two statements add the capital city of " Italy " to the dictionary? (Choose 2.)
- AOption A:
capitalCities[ " Rome " ] = " Italy "
- BOption B:
capitalCities.append([ " Italy " : " Rome " ])
- COption C:
capitalCities[ " Italy " ] = " Rome "
- DOption D:
capitalCities = capitalCities + [ " Italy " : " Rome " ]
- EOption E:
capitalCities.updateValue( " Rome " , forKey: " Italy " )
Show answer and explanation
Correct answer: C, E
Comprehensive and Detailed Explanation From App Development with Swift domains:
This question falls under Swift Programming Language , specifically the domain for managing data using collection types , with emphasis on dictionaries . In Swift, a dictionary stores data as key value pairs , so in this example the country name is the key and the capital city is the value. To add a new entry, Swift supports two standard approaches. The first is subscript assignment , which is shown in option C : capitalCities[ " Italy " ] = " Rome " . Apple’s documentation explains that you can add a key-value pair to a dictionary by assigning a value for a new key through the dictionary subscript.
The second correct approach is option E : capitalCities.updateValue( " Rome " , forKey: " Italy " ). Apple documents that updateValue(_:forKey:) updates the value for an existing key, or adds a new key-value pair if the key does not already exist . That makes it equally valid for inserting " Italy " : " Rome " into the dictionary.
The incorrect options fail for different reasons. A reverses the key and value, making " Rome " the key and " Italy " the value. B is wrong because append is used with arrays, not dictionaries. D is not the standard valid insertion syntax for Swift dictionaries in this context; Swift’s documented mutation approaches here are subscript assignment and updateValue. Therefore, the two correct answers are C and E .