class C{
var b:[String]?
subscript(i:Int)->String?{
get{
return b?[i]
}
set{
b?[i] = newValue! // notice the unwrapped “!” here
}
}
}
In the code, I put a exclamation mark "!" to unwrap the newValue,
Because newValue is the same type of the return value of subscript which is String?.
If I don't put the exclamation mark "!" it will report error:
"
error: cannot assign value of type 'String?' to type '
String'b?[i] = newValue
"
Question: b?[i] is obviously an optional String value String?, how come it is of type String.
I wonder it was a bad error code