It works fine to cast a Swift String
as an NSString
.
let string = "some text"
let nsString = string as NSString
But when I do
let string = "some text"
let nsMutableString = string as NSMutableString
I get the error
'String' is not convertible to 'NSMutableString'
How to I convert it?
You cannot cast a String
as an NSMutableString
, but you can use an NSMutableString
initializer.
let string = "some text"
let nsMutableString = NSMutableString(string: string)