我是 Objective-c 和 ios 开发的新手,正在寻找最佳实践。我想有不同的常数BASE_URL
,这取决于调试和生产环境..
我希望它看起来像,例如Constants.m:
#import "Constants.h"
static NSString *BASE_URL = @"http://localhost:3000";
NSString * const API_URL = [BASE_URL stringByAppendingString:@"/api"];
和.pch文件:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Constants.h"
#endif
但是编译器说我在这里错了-NSString * const API_URL = [BASE_URL stringByAppendingString:@"/api"];
Initializer 元素不是编译时常量