For some strange reason, the escape sequences \ n and \ r do not seem to work in my code. I want to write each NSString in a new line in the file, but it just adds the last line in one line. Here is the code:
for (Entry *entry in self.entries) { NSString *path = @"/Users/me/File.txt"; NSString *string = (@"%@\r\n", [entry thisEntry]); NSFileHandle *fh = [NSFileHandle fileHandleForWritingAtPath:path]; [fh seekToEndOfFile]; [fh writeData:[string dataUsingEncoding:NSUnicodeStringEncoding]]; [fh closeFile]; }
Am I doing something wrong? Forgive me, as I am new to Objective-C.
source share