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?
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?
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:]
.
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.
initWithContentsOfFile:error:
initWithContentsOfURL:error:
writeToFile:atomically:
writeToURL:atomically:
and so on, NSData NSString NSImage and so on all support these methods