Tag: iOSSDK/ファイルIO
let path : String = NSBundle.mainBundle().pathForResource("sample", ofType: "txt")! do { let text = try String(contentsOfFile: path, encoding: NSUTF8StringEncoding) textView.text = text print(text) } catch {
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); }