我有一個非常長的URL列表,我的應用程序用來從服務器檢索數據。目前,每個URL都有自己恆定的,即:如何正確管理我的應用程序網址?
// constants.h
extern NSString * const profileUrl;
// constants.m
NSString * const profileUrl = @"http://api.site.com/profile";
.
.
這不是什麼大不了的事,但如果我想改變的基礎URL,我得進去,手動替換所有的人都在每個不變。如果可以的話,我想遵循DRY哲學(不要重複自己)。就像我在做可能的事情。
// constants.h
extern NSString * const baseUrl;
extern NSString * const profileUrl;
// constants.m
NSString * const baseUrl = @"http://api.site.com/";
NSString * const profileUrl = [NSString stringWithFormat:@"%@%@", baseUrl, @"profile"];
如果是這樣,是否有一個標準的方式來處理你的應用程序網址有序的方式?你使用的一些技術是什麼讓你的生活更輕鬆?
這似乎是我的情況中最優雅的解決方案。非常感謝你! – Ken