top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to create mutable or immutable Array/Dictionary in SWIFT

0 votes

How to create mutable or immutable Array/Dictionary in SWIFT as like in objective c

posted Jul 22, 2014 by Manjunath

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Immutable Array :

let array = NSArray(array: ["First","Second","Third"])

Mutable Array :

var array = ["First","Second","Third"]

Immutable Dictionary :

let dictionary = ["Item 1": "description", "Item 2": "description"]

Mutable Dictionary :

var dictionary = ["Item 1": "description", "Item 2": "description"]
answer Aug 4, 2014 by Raju
Similar Questions
0 votes

Dictionary gives error when i tried to re-assign values.

  var dictionary = [:]
    dictionary = ["one":"Hello","two":"Good","three":"Morning"]
    dictionary["two"] = "Night"

And error is

Playground execution failed: error: <REPL>:35:17: error: cannot assign to the result of this expression
dictionary["two] = "Night"
~~~~~~~~~~~~~~~ ^
+1 vote

How to declare single parameter which accept multiple values.

+1 vote

How to use default values for parameter in function. What will happens when value is not passed for a default parameters.

0 votes

I am facing situation to use external parameter name to a function parameter name .. How to achieve this

0 votes

Is it possible to set multiple return type for function in SWIFT. If yes please provide me syntax .