Posts

Showing posts from 2021

Swift Dictionary

What is Swift Dictionary? Swift Dictionary is a hash table providing fast access to the keys it contains.   Entries in the table are identified with the help of key, which is hash able and the entries accessed are objects. In Swift Dictionary is structure with Key and Value, where Key is Hashable as can be understood from the Apple Document  @frozen   struct   Dictionary < Key ,   Value >   where   Key   :   Hashable Let's perform some CRUD operations on a dictionary. Create a dictionary. There are multiple ways to create a dictionary.  Style 1: var userIdNamesDictionary: Dictionary < String , String > = [:] Style 2: var userIdNamesDictionary2:[ String : String ] = [:] Style 3:  Inferring based on the values in the dictionary during initialization. The entry before the colon is key and after the colon is value corresponding to the key, we can add multiple key and value pairs by separating it with comma. var userIdNamesDictionary3 = [ "1" : "Adam",