iPhone - int to NSData?
To write:
int i = 1;NSData *data = [NSData dataWithBytes: &i length: sizeof(i)];[data writeToFile: [documentsDirectory stringByAppendingString: @"someFile"] atomically: YES]
and to read back:
NSData *data = [NSData dataWithContentsOfFile: [documentsDirectory stringByAppendingString: @"someFile"]];int i;[data getBytes: &i length: sizeof(i)];
However, you really should be using NSUserDefaults
for something like this, in which case you'd be doing:
[[NSUserDefaults standardUserDefaults] setInteger: i forKey: @"someKey"]
to write, and
int i = [[NSUserDefaults standardUserDefaults] integerForKey: @"someKey"];
to read.