NSBundle
NSBundle provides methods for locating and handling application (and tool) resources at runtime.
런타임에 리소스의 위치와 응용프로그램에 대한 핸들링을 지원한다.
리소스의 경로정보를 받아올 수 있는 방법
아래와 같이 사용하면 경로정보를 받을 수 있다.
NSString * file_path = [[NSBundle mainBundle] pathForResource: @"FILE_NAME" ofType: @"FILE_EXT" inDirectory: @"FILE_DIR"];
참고로 FILE_NAME
은 파일 이름, FILE_EXT
은 파일 확장자, FILE_DIR
은 파일이 존재하는 디렉터리이다.
파일 확장자에 온점(.
)은 붙이지 않는다. 파일이 존재하는 디렉터리의 마지막에 슬래시(/
)를 붙인다.
Localized String
국가별 문자열을 적용하기 위한 API는 NSBundle.h
에 아래와 같이 정의되어 있다.
#define NSLocalizedString(key, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
#define NSLocalizedStringFromTable(key, tbl, comment) \
[[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
[bundle localizedStringForKey:(key) value:@"" table:(tbl)]
#define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment) \
[bundle localizedStringForKey:(key) value:(val) table:(tbl)]