I think you are trying to write directly array to file.
convert your array in string format.
NSString *tagsCompleteStr = [tags componentJoinedByString:@" "]; [tagsCompleteStr writeToFile:fileAtPath atomically:NO];
Hope this will help.
質問
for(int x = 0; x < [tags count]; x++){
NSString* tagsValue = [[NSString alloc] initWithFormat:@"%d: %f", 1,
[[tags objectAtIndex:x]doubleValue]];
[[tagsValue dataUsingEncoding:NSUTF8StringEncoding] writeToFile:fileAtPath
atomically:NO];
}
i understand that writeToFile will replace the file itself so it would of give the final value of the array value. How could i approach this i've been trying to get this around my head for a few hours but i've had no luck thanks! :)
解決
I think you are trying to write directly array to file.
convert your array in string format.
NSString *tagsCompleteStr = [tags componentJoinedByString:@" "];
[tagsCompleteStr writeToFile:fileAtPath
atomically:NO];
Hope this will help.
他のヒント
The following code will add the tagsValue string at the end of the file,
Make sure you have already created the file.
for(int x = 0; x < [tags count]; x++){
NSString* tagsValue = [[NSString alloc] initWithFormat:@"%d: %f", 1, [[tags objectAtIndex:x]doubleValue]];
NSFileHandle *myHandle = [NSFileHandle fileHandleForWritingAtPath:fileAtPath];
[myHandle seekToEndOfFile];
[myHandle writeData:[tagsValue dataUsingEncoding:NSUTF8StringEncoding]];
}