I have an optional object1 of Type1. I would like to convert it to an array of Type2 (non optional, empty if object1 was nil).
Type2 objects are constructed with Type1 objects.
So I've tried like this :
func convert(object1: Type1?) -> [Type2] {
object1.map {
[
Type2($0)
]
}
}
But I get this error :
Cannot convert return expression of type '[Type2]?' to return type '[Type2]'
Note: Type2 initialiser cannot take a an optional value as parameter.
if anyone has an idea, thanks in advance