Swift Dictionaries
Swift Dictionaries
Dictionaries are the same array but the array is only store value. dictionaries are store key and value.
Dictionaries are accessed by key, and key is user defined
key is unique identifier if you are not using the unique key then at a time access to two value.
if You are create a empty dictionary using following initializer syntax:
var dictionariesname:Dictionary = [keyType:valueType]()
Example :
var frined:Dictionary = [Int:String]()
if you are create a dictionary with value using following initializer syntax:
var dictionariesname:Dictionary = ["key":"value","key","value"]
Example :
var friendandage:Dictionary = ["parth":"20","hardik":"23","fevin":"22","vijay":"21"]
access dictionaries value by key
Syntax:
dictionariesname["key"]
Example:
friendandage["hardik"]
if you are add same value in dictionary following this syntax:
dictionariesname["key"] = "value"
Example:
friendandage["hiren"] = "25"
if you are update value in dictionary following this syntax:
dictionariesname["oldkey"] = "value"
Example:
friendandage["parth"] = "30"
If you are deleted a value in dictionary following this syntax:
dictionariesname["oldkey"] = nil
Example:
friendandage["fevin"] = nil
If you are print dictionary in reverse following this syntax:
dictionariesname.reverse()
your dictionary is print in reverse order
If you count a value in dictionary in following this syntax:
friendandage.count
If you are remove all value in dictionary following this syntax:
friendandage.removeAll()
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment