Search code examples
iosswiftnsmutablestringunichar

Append unichar to NSMutableString in Swift


I want to append a unichar to NSMutableString. I have

var outputString: NSMutableString = "Some string" 
let letterA: unichar = 0x1820

I saw the question Appending unichar to NSMutableString. The accepted answer (in Objective C) says:

[s appendFormat:@"%C", c];

but I can't figure out the Swift syntax. The documentation doesn't help much, either.

I even tried

outputString += letterA

but that also didn't work.

Note: I'm not trying to append a Swift String or append a Swift Character.


Solution

  • Use the same method appendFormat in swift like this

    Rewriting your code to elaborate

        var outputString: NSMutableString = "Some string"
        let letterA: unichar = 0x1820
        outputString.appendFormat("%C", letterA)