In Swift I have a function that returns some kind of object. That object is optional. When it does not exist, I suppose I should return nil, but Swift forbid me to do so. Following code is not working:
func listForName (name: String) -> List {
if let list = listsDict[name] {
return list
} else {
return nil
}
}
It says : error: nil is incompatible with return type 'List'
But I don't want to return something like empty List object, I want to return nothing when optional is empty. How to do that?