close

NSBundle的用法

from http://fecbob.pixnet.net/blog/post/36157949-nsbundle%E7%9A%84%E7%94%A8%E6%B3%95--

NSBundle的物件可以獲取應用程式安裝目錄的附件。

附件包括了,當前應用程式下,所有的檔。(圖片、屬性清單等)




獲取XML檔
NSString *filePath = [[NSBundle mainBundle] pathForResouse:@"re" ofType:@"xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];




獲取TXT檔

 

NSString *filePath = [[NSBundle mainBundle] pathForResouse:@"myFile" ofType:@"txt"];
NSData *data = [NSData dataWithContentsOfFile:filePath];



獲取屬性清單

 

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ViewControllers" ofType:@"plist"]];
arrow
arrow
    全站熱搜

    zer931 發表在 痞客邦 留言(0) 人氣()