How To Use a Swift Dictionary

Beginner Tutorial for Swift

Swift Arrays are a collection where each item uses a numerical index. Code below returns the value “signs”

var categories = ["signs","roads","behaviour"]
categories[0]

With Dictionary instead of using numerical indexes, you can specify a unique key. Code below returns the value “signs”

var categories = ["basics" : "signs", "intermediate": "roads", "advanced":"behaviour"]
categories["basics"]

Leave a Reply

Your email address will not be published. Required fields are marked *