Shortcuts in Objective-C to concatenate NSStrings

前端 未结 30 3099
伪装坚强ぢ
伪装坚强ぢ 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:45

    If you have 2 NSString literals, you can also just do this:

    NSString *joinedFromLiterals = @"ONE " @"MILLION " @"YEARS " @"DUNGEON!!!";
    

    That's also useful for joining #defines:

    #define STRINGA @"Also, I don't know "
    #define STRINGB @"where food comes from."
    #define JOINED STRINGA STRINGB
    

    Enjoy.

提交回复
热议问题