Build a list of constants variable from other constants

前端 未结 3 1155
长情又很酷
长情又很酷 2021-01-18 15:27

I\'ve just read all of objective-c global constants variables Q&A but I found them inappropriate to my problem.

I need a list of variable like t

相关标签:
3条回答
  • 2021-01-18 16:10

    I don't have access to a MAC now ... can you just try this..

    in .h

    NSString *baseURLString;
    extern NSString *const baseURL;
    

    in .m

    baseURLString= @"http://example.org";
    NSString *const baseURL= [NSString stringWithFormat:"%@", baseURL];
    

    I am not sure of this will work..

    And also have you seen this answer at SO ... it has all the approaches I know of... Constants in Objective-C

    0 讨论(0)
  • 2021-01-18 16:19

    I know it's old-fashioned but I'd just use preprocessor macros and let constant string concatenation handle it.

    #define baseURL @"http://example.org"
    #define mediaURL baseURL@"/media/"
    
    0 讨论(0)
  • 2021-01-18 16:22
    #define API_ROOT_URL @"https://www.example.org/api"
    NSString *const OAuthUrl = API_ROOT_URL @"/oauthToken";
    

    See also.

    0 讨论(0)
提交回复
热议问题