How to append a NSMutableString with a NSMutableString?

后端 未结 4 1569
生来不讨喜
生来不讨喜 2020-12-19 00:43
NSMutableString *str, *str1;

//allocation here

i am using [str appendString:str1] is not working. [str appendFormat:str

4条回答
  •  时光取名叫无心
    2020-12-19 01:29

    Swift version

    Although in Swift it is not the general practice to use NSMutableString, it may at times be necessary. This is how you would do it:

    var str: NSMutableString = NSMutableString()
    var str1: NSMutableString = "some value"
    str.appendString(str1 as String) // str = "some value"
    

    Note that the usual way to append a string in Swift is like this:

    var str = ""
    let str1 = "some value"
    str += str1
    

    where str and str1 are inferred to be of type String.

提交回复
热议问题