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.

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.

– bpapa May 7 '09 at 20:05 No; although you can, it's also safe (and common) to store app behavior information there, even if there is no user interface available. Safari on OS X uses the user defaults to save things such as last window size, whether developer features are enabled, and so on. – Benjamin Pollack May 7 '09 at 20:07.

I'm making an iPhone app where I want to save state of the Application. This includes an int property which I'm persisting to a file on its own. I have it written and working, but I know the way I did it was a bit hacky, converting the int to a String and then NSData.

Can anybody suggest a better way?

Teens use drugs quite often to be popular and fit in with the other people that use them. Others are looking for things to help them cope with the hardship of being a teen or specific problems in their lives.

From when you were a teenager. Here you'll find out some of the most common situations in which teens drink and use drugs? And what you can do about it.

Why do teens use drugs or drink alcohol? Some of the reasons may seem obvious: wanting to fit-in, to socialize, or wanting to hide from pain. But understanding the feelings behind these reasons for using drugs — as well as how everyday teen life comes into play — can be quite eye-opening for parents.

This section will help you become more aware and offer tips for talking to your teen and for putting important guidelines in place.

Sharing them with the world means that your work can continue to be shared - and that more people than simply a professor or TA will see your work You stand to make a profit from things you publish on HubPages You can get valuable feedback from people who read your papers on HubPages You may be 'found' through your articles on HubPages (Writers on HubPages have been discovered by publications, news networks, and potential employers who found them through Hubs they published) Your resume can benefit form an online presence. Knowing that you will be publishing your work online can raise your own standards with your work (It may be hard to put hours and hours into a paper that only one person will read, but that effort seems worth it if your work is destined for a larger audience) You may find a new source of motivation to get papers and school projects done (Schoolwork can be a drag, but when you know you can publish and profit form your work, it isn't so bad!).

Getting Started on HubPages: Step #1 - Create Great Content.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions