Swift Basics: Dictionaries
Learn about dictionaries in the Swift Programming Language
Let’s talk about Swift Dictionaries.
Imagine that you have a bunch of words and definitions written on index cards. You want to be able to quickly look up the definition of a word whenever you need to, so you put all of the index cards into a special box.
This special box is like a dictionary in the Swift programming language. It’s a way to store and organize information so that you can easily find what you’re looking for.
Each index card in the box has a word written on one side and a definition written on the other side. In a dictionary in Swift, each “index card” is called a key-value pair. The word is the “key” and the definition is the “value.”
To find the definition of a word in the box, you would look through the index cards until you find the one with the word you’re looking for written on it. Then, you would flip the index card over to see the definition.
In the same way, to find a value in a dictionary in Swift, you would use the key to look up the value. For example, if you have a dictionary with the keys “apple,” “banana,” and “cherry,” and you want to find the value for the key “banana,” you would look through the dictionary until you find the key “banana” and then you would get the value associated with it.
Here’s some example code to create and use a dictionary in Swift:
~~~
📱 If this article helps you, help someone else and share it.
Get Stanley Miller ’s stories in your inbox
Join Medium for free to get updates from this writer.
👇 Looking for Swift/SwiftUI secrets? Try my book 👇
Your Guide to Mastering Swift, One Tip at a Time
I wrote Tips, Tricks, and Other Bits to share everything I’ve learned on my path from working at TSA to becoming a successful iOS freelancer. I know firsthand how confusing and overwhelming coding can feel when you’re just starting out. That’s why I packed this book with real-world strategies and lessons I wish I’d had when I began. Whether you’re brand new or prepping for the job market, this guide is designed to fast-track your Swift journey. Coding is hard but let’s make it easier.
What’s Inside?
- My proven tips, tricks, and shortcuts for Swift success.
- Clear explanations of Swift fundamentals you need to master.
- Solutions for real-world coding challenges developers face.
- Pro-tips on code organization and writing clean, readable code.
- Essential Xcode and SwiftUI tools to streamline your projects.
This isn’t just another programming book — it’s a roadmap based on my personal experience. Whether you’re aiming for your first app or your 100th, I’ll show you how to simplify your learning, tackle tough problems, and fast-track your career.
P.S — Help yourself and help others! 10% of all sales are donated to the Child’s Play Charity.










