2

As Objective-C is superset of C, I guess I can use fopen/fread/fwrite/fprint... just like I do with C.

Does that mean that Objective-C doesn't have its unique file processing function?

prosseek
  • 182,215
  • 215
  • 566
  • 871
  • Does this link help out? http://www.cocoabuilder.com/archive/cocoa/199087-file-processing-with-obj-cocoa.html – Dbz Feb 27 '11 at 23:23

3 Answers3

3

Objective-C doesn't have file handling, nor does C. However, the C Standard Library does. And if you want to use Objective-C, you can use the C Standard Library.

Objective-C is mostly used with Foundation, so -[NSData writeToURL:atomically:] and -[NSString writeToURL:atomically:encoding:error:] can be used if you link to the Foundation framework.

For reading files the methods are -[NSData initWithContentsOfURL:options:error:] and -[NSString initWithContentsOfURL:encoding:error:].

0

Look at the NSFileManager and NSFileHandle classes for a start. Many other classes, such as NSData, also have methods to read data from a file and write data to a file.

Anomie
  • 92,546
  • 13
  • 126
  • 145
0

initWithContentsOfFile:error:

initWithContentsOfURL:error:

writeToFile:atomically:

writeToURL:atomically:

and so on, NSData NSString NSImage and so on all support these methods

Antwan van Houdt
  • 6,989
  • 1
  • 29
  • 52