Saving an Mutable Array into file via writeToFile

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! :)

Answers


I think you are trying to write directly array to file.

  1. 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]];
   }

Need Your Help

Need to tweak my FTS4 SQLite query

android sql sqlite full-text-search fts4

The query below doesn't work on Android and throws the following exception

Conversion Big Integer <-> double in C++

c++ math assembly

I am writing my own long arithmetic library in C++ for fun and it is already pretty finished, I even implemented several Cryptogrphic algorithms with that library, but one important thing is still