Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa read/write a file

Tags:

file

xcode

cocoa

How do I write to a txt file, so I would like a string value inside the document which I later want to read.

What I want to do is basically just a demo app, I want a specific piece of text in a NSTextField to be written into a file and then be read from the file and the contents of the file to be placed in a second NSTextField.

like image 891
Lenny Magico Avatar asked Sep 21 '26 09:09

Lenny Magico


1 Answers

You can use NSString's -writeToFile:atomically:encoding:error: or -writeToURL:atomically:encoding:error: methods to write your string to a file. There are plenty of other ways, but these are about as easy as it gets. There are corresponding methods for reading a file into a string.

like image 199
Caleb Avatar answered Sep 24 '26 03:09

Caleb