I have following code:
class User {
var listsDict : [String : List]!
func addList (list : List) -> Void {
print(list.name)
listsDict[list.name] = list
}
func listForName (name: String) -> List? {
return listsDict[name]
}
}
class List {
let name : String
var movies : Set<String>
init(name: String){
self.name = name
movies = Set<String>()
}
func printList (){
print(movies)
}
}
var list = List(name: "List")
list.movies = Set<String>(["LOTR", "SAW", "POC"])
list.printList()
var johny = User()
johny.addList(list: list)
When i call johny.addList(list: list)
i got an error:
unexpectedly found nil while unwrapping an Optional value
But there is a value. I created instance of list previously and even print in log name of list (and it successfully printed). Why i got an error?