TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Array or Set using keypairs

Forums > 100 Days of Swift

Working through Arrays and Sets I find that when creating an array that uses a keypair i.e. var questions = [String:String] neither append or insert are available. How do you append or update an Array with keypairs?

Thanks in advance.

Werner

2      

That's not an array, it's a Dictionary. See this cheatsheet for helpful tips.

Basically, though, you add to a Dictionary using subscript syntax:

var dict: [String: String] = [:]
dict["Charlotte"] = "Grote"
dict["Shauna"] = "Wickle"
print(dict)
//["Charlotte": "Grote", "Shauna": "Wickle"]

3      

Thank you. The cheatsheet is very helpful.

Werner

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.