How to create constant NSString by concatenating strings in Obj-C?

前端 未结 3 797
野的像风
野的像风 2020-12-18 20:10

I\'m trying to instanciate a constant NSString by concatanating other NSString instances.

Here is what I\'m doing in my implementation file :

static          


        
3条回答
  •  余生分开走
    2020-12-18 20:34

    I thought there must be a way to do this but the best I could do was using a #define directive. For example,

    // Define the base url as an NSString
    #define BASE_URL @"http://www.milhouse.co.uk/"
    
    // Now the derived strings glued by magic
    NSString *const kBaseURL    = BASE_URL;
    NSString *const kStatusURL  = BASE_URL @"status.html";
    NSString *const kBalanceURL = BASE_URL @"balance.html";
    

提交回复
热议问题