Hey guys, A question I am kind of stuck on. Is there anything better to use then an NSString for a small paragraph of text? So for example, a user inputs a few sentences then I want to store that text into a variable. Is the only thing I can use an NSString or is there something better and more effiecient? The reason I ask is because sometimes if the input is to big my program crashes.
Thanks a lot.
NSString (or better yet, NSMutableString) is probably your best option. It's extremely doubtful that 1 paragraph of text would take up too much memory and crash the app. Keep in mind that using ASCII encoding, 1 character is usually mapped to 1 bite in memory. This changes depending on the string encoding you're using (probably UTF8), but you would need at least hundreds of thousands of characters in your string to use even just 1 MB of RAM. Keep in mind also that the UITextView's text property is an NSString as well, and is using just as much memory as your string is.
What exception are you getting when the crash occurs?
If you're using UITextView for the text entry, you could set your string variable to the contents of your text view at predefined intervals, and in viewWillDisappear (Code: [myMutableString setString: myTextView.text] ). You could also use the delegate for UITextView to update your variable every time the user makes a change to the text view's text.
To easily persist the string, you can use [myString writeToFile

athIWantToSaveTo] to save a PLIST. To set your string to the saved version, just use [myMutableString setString: [NSString stringWithContentsOfFile: pathISavedPLISTTo].
If that's not enough, you could also look into using Core Data or sqlite, but PLIST's should be fine for most apps that are only saving text (or simple NSDictionary's or NSArray's).