Leon
Leon

Reputation: 417

How can I save the content of a UITextView?

in my app I want to save the text that was typed in in a UITextView. How can I do this?

Thanks for you help.

Leon

Upvotes: 1

Views: 1164

Answers (2)

DLende
DLende

Reputation: 5242

Create a dictionary and add your text with the key to the dictionary

NSDictionary *dict =  [[NSMutableDictionary alloc] init];
NSString *str = myTextView.text;
[dict setObject:str forKey:@"theText"];

Register your dictionary to NSUserDefaults

[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
[[NSUserDefaults standardUserDefaults] synchronize];
[dict release];

Retrieving it in your whole app:

NSString *theText = [[NSUserDefaults standardUserDefaults] stringForKey:@"theText"];

Upvotes: 0

Peter DeWeese
Peter DeWeese

Reputation: 18343

NSString *theText = myTextView.text;

Thats how to get the text from it. You can save it in a variety of places, but where do you want to save it? The user defaults? Core Data? A plaintext file? A properties file? An xml file? In a web app?

Upvotes: 1

Related Questions