in Technology by
What is a dictionary in Swift ?

1 Answer

0 votes
by

Dictionaries are an association of an unordered collection of key-value pairs. Each value is associated with a unique key, which is a hashable type such as a number or string. We can use the dictionary concept in swift programming language whenever we want to obtain the values based on a key value.

Syntax of Swift Dictionaries:

Following is the syntax of defining a dictionary in the Swift programming language.

Dictionary<Key, Value> ()

Or

[Key: Value] ()

Creating Dictionaries in Swift:

Following are the different ways of creating a dictionary with key-value pairs in the declaration.

// using Dictionary
Var names = Dictonary<String,Int> ()
Names = [“Ajay”: 1, “Mohit”: 2]
print(names)
// it prints [Ajay: 1, Mohit: 2]

Related questions

0 votes
    I'm having trouble with understanding how to properly do unwrapping in Swift. Here is the situation: I have ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    How to change Swift version from 5 to 4 in Xcode?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    How do I see which version of Swift I'm using?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    How to iterate a loop with index and element in Swift?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    Can we use both swift (.swft) and objective c (.h .m) in same xcode project ?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    How do I call Objective-C code from Swift?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    What is a GUARD statement? What is the benefit of using the GUARD statement in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is the use of double question mark “??” in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is a delegate in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is a Protocol in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What is the difference between Let and Var in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    What are the control transfer statements that are used in iOS swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
0 votes
    What type of objects are basic data types in swift?...
asked Nov 30, 2020 in Technology by JackTerrance
0 votes
    Is Swift an object-oriented programming language?...
asked Nov 30, 2020 in Technology by JackTerrance
...