Friday, February 1, 2013

File operation in objective C

You can use the standard c functions.
fopen(), fread(), fwrite(), open(), read() and write().


You can write objects of NSArray, NSDictionary, etc directly into file. There is having separate method ex writetoFile: method.

Example if u wrote array of string in Array and if u wrote that array into file. File will be having stuff like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>this is test 1</string>
<string>this is test 2</string>
<string>this is test 3</string>
</array>
</plist>

Some object have serialization and deserialization method which will write directly to file.

 An NSCoder  is an abstract class that defines a bunch of useful methods for converting your objects into an NSData  and back. So this is useful in serialization and de serialization. We are using  We’ll be NSKeyedArchiver  and NSKeyedUnarchiver classes which are subclass of  NSCoder.

NSKeyedArchiver is uses key/value pairs to hold an object’s information. It uses the name of the variable as key easy for decode also.

0 comments:

Post a Comment

About

Powered by Blogger.