Shortcuts in Objective-C to concatenate NSStrings

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

    How about shortening stringByAppendingString and use a #define:

    #define and stringByAppendingString
    

    Thus you would use:

    NSString* myString = [@"Hello " and @"world"];
    

    Problem is that it only works for two strings, you're required to wrap additional brackets for more appends:

    NSString* myString = [[@"Hello" and: @" world"] and: @" again"];
    

提交回复
热议问题