A
A
Alexey2019-01-15 15:13:20
Swift
Alexey, 2019-01-15 15:13:20

What will be in the dictionary when you assign an object to it through a key?

I don't know if I phrased the question correctly. I'm just learning.
There is this code:

class List {
  let name: String
  var movies: [String] = []

  init(name: String) {
    self.name = name
  }
}

class User {
    var lists: [String: List] = [:]

  func addList(_ list: List) {
    lists[list.name] = list
  }
}

let jane = User()
var actionList = List(name: "Action")

jane.addList(actionList)

jane.lists["Action"]?.movies.append("Rambo")
jane.lists["Action"]?.movies.append("Terminator")

I can't imagine what will end up in the lists dictionary? What will this dictionary look like after it has been populated with the above code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nick V, 2019-01-15
@half-life

Something like this
5c3e1d8eaab88046413772.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question