#author("2016-05-18T15:27:52+09:00","default:wikiwriter","wikiwriter") &tag(iOSSDK/ファイルIO); *目次 [#j9477b9c] #contents *参考情報 [#b77138e7] -[[How To Read a File From Your Application Bundle | iPhone Development Blog:http://iphoneincubator.com/blog/data-management/how-to-read-a-file-from-your-application-bundle]] -[[davedelong/CHCSVParser · GitHub:https://github.com/davedelong/CHCSVParser]]…オープンソースのライブラリ *テキストファイルの読み込み [#edc85727] -バンドルリソースに含まれる"sample.txt"を読み込む例 #pre{{ let path : String = NSBundle.mainBundle().pathForResource("sample", ofType: "txt")! do { let text = try String(contentsOfFile: path, encoding: NSUTF8StringEncoding) textView.text = text print(text) } catch { }} *CSVの読み込み [#vcd3f2bd] -単純なCSVと仮定した上での読み込み #pre{{ NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"csv"]; NSString *text = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; NSArray *lines = [text componentsSeparatedByString:@"\n"]; NSLog(@"line count: %d", lines.count); for (NSString *row in lines) { NSArray *values = [row componentsSeparatedByString:@","]; NSLog(@"value count: %d", values.count); } }}