可能重复:
objective C: write in a csv (txt) string contained in some textfield
我有这个代码在csv文件(txt)中写一个字符串
NSMutableString *csvString = [NSMutableString stringWithString:textfield1.text];
[csvString appendString:@"#"];
[csvString appendString:textfield2.text];
[csvString appendString:@"#"];
[csvString appendString:dtextfield3.text];
[csvString appendString:@"#"];
[csvString appendString:textfield4.text];
[csvString appendString:@"#"];
[csvString appendString:textfield5.text];
[csvString appendString:@"#"];
[csvString appendString:textfield6.text];
[csvString appendString:@"#"];
[csvString appendString:textfield7.text];
[csvString appendString:@"#"];
if (uiswitch.on) { //switch
[csvString appendString:@"1"];
}
else [csvString appendString:@"0"];
[csvString appendString:@";"];
NSString *resourceFileName = @"Client";
NSString *pathToFile =[[NSBundle mainBundle] pathForResource: resourceFileName ofType: @"txt"];
NSError *error;
NSString *fileString = [NSString stringWithContentsOfFile:pathToFile encoding:NSUTF8StringEncoding error:&error];
if (!fileString) {
NSLog(@"Error reading file.");
}
[csvString writeToFile:pathToFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
但它不起作用,为什么???