Skip to content

Instantly share code, notes, and snippets.

@kyle-go
Last active August 29, 2015 13:57
Show Gist options
  • Save kyle-go/9803163 to your computer and use it in GitHub Desktop.
Save kyle-go/9803163 to your computer and use it in GitHub Desktop.
http header宏定义问题,解决方案
//复杂的宏实现,效率确实比较高一些,但有点小瑕疵,需要继续分割“//”才能消除警告
#define _ToStr(x) #x
#define __ToStr(x) _ToStr(x)
#define HTTP_HEADER http:/\/www.google.com/
#define WEBSITE_INDEX1 @__ToStr(HTTP_HEADER)"index1.html"
#define WEBSITE_INDEX2 @__ToStr(HTTP_HEADER)"index2.html"
//NSLog(@"%@", WEBSITE_INDEX1);
//NSLog(@"%@", WEBSITE_INDEX2);
//与其搞那么复杂的宏,不如来点简单好理解的,如果您硬要效率的话,我只能呵呵了。
#define URL(a) [NSString stringWithFormat:@"%@%@", BASE_URL, a]
#define BASE_URL @"http://www.google.com/"
#define WEBSITE1 URL(@"index1.html")
#define WEBSITE2 URL(@"index2.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment