Guest User

Untitled

a guest
Oct 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. - (void) writeToFile: (NSString *) targetString
  2. {
  3. //_loggingString holds the data, which keeps on accumulating as the user performs operations. At some point of time (callbacks from API's I call this method, to actually, write this string in the file and clear this string afterwards.)
  4. NSString *oldString = [_loggingString copy];
  5.  
  6. _loggingString = [oldString stringByAppendingString:targetString];
  7.  
  8. if (![[NSFileManager defaultManager]fileExistsAtPath:@"somePath"])
  9. {
  10. [[NSFileManager defaultManager]createFileAtPath:@"somePath" contents:nil attributes:nil];
  11. }
  12.  
  13. NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:@"somePath"];
  14.  
  15. [fileHandle seekToEndOfFile];
  16.  
  17. [fileHandle writeData:[_loggingString dataUsingEncoding:NSUTF8StringEncoding]];
  18.  
  19. _loggingString = @"";
  20. }
Add Comment
Please, Sign In to add comment