Shortcuts in Objective-C to concatenate NSStrings

前端 未结 30 3106
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 07:03

Are there any shortcuts to (stringByAppendingString:) string concatenation in Objective-C, or shortcuts for working with NSString in general?

30条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 07:41

    Shortcut by creating AppendString (AS) macro ...

    #define AS(A,B)    [(A) stringByAppendingString:(B)]
    NSString *myString = @"This"; NSString *test = AS(myString,@" is just a test");

    Note:

    If using a macro, of course just do it with variadic arguments, see EthanB's answer.

提交回复
热议问题