saving text from uitextview to plist - iphone

for my application i am able to read the description of a place selected from the table row and display it in the uitextview. but what i needed to do next is able to save content edited by user in the uitextview to plist. need some guide because i had been searching for it but in vain..thanks

You don't need to use a plist to store a string, you can use -[NSString writeToFile:atomically:encoding:error:] method, and just create a single file.
If you're dead set on creating a plist, you can use the NSPropertyListSerialization class to read and write plists.

Related

copy paste text and image both to clipboard in iphone app

I am working on an app where I want to copy some text and image and allow user to paste it anywhere. I know it is done using UIPasteboard and I have implemented copying of image but now I want to copy image and text both and then let user paste it. There can be several images and text messages which can come in any order. It is like a paragraph being written with text and images. Is this possible? Can someone suggest me how can I achieve it?
Regards
Pankaj
You can put anything you wish in the pasteboard, including multiple entries like of type UIPasteboardTypeListString and another of type UIPasteboardTypeListImage, and even another of type #"My Made-Up Type". Think of it as a shared mutable dictionary.
It's up to the receiving application to understand what to do with them.

Create a plist file per item

Does anybody know how to create a plist file per item in an array, so for example I have an add button which lets me add an item, how can I create a plist per item added and how can I then retrieve it back to view the data?
I would include a PLIST in your app bundle and copy it (with a different name each time) to the documents directory as needed. Now that you have a working PLIST, it's as simple as reading your PLIST into a NSMutableDictionary or NSMutableArray, editing it, and writing the results back to the PLIST.

Where do I put text, instructions, description etc. in an iPhone program?

When an iPhone program has something like a paragraph or a set of instructions that need to be displayed on screen--basically anything that is longer than two sentences, where does it go?
Should it be stored as an NSLocalizedString (is this stored in the info.plist? I tried searching documentation--I'm a beginner and don't quite understand where that goes)?
Should it simply be hard-coded into the UITextView or UILabel that contains it?
Should it be defined as a constant then referenced in the UITextView/UILabel?
Should it be placed in a .txt file then referenced? (http://stackoverflow.com/questions/2506594/where-to-put-text-files-for-iphone-uitextview)
If you are thinking about localizing the text at all, I'd put it into a strings file:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html
You could also put it into a plist and read the plist file at runtime from the bundle. Generally try to keep the info.plist clean.
I would put such items in a plist file ad read it in.

What are UILabel's initWithCoder encoded keys?

I have a subclass of a UILabel that overloads initWithCoder and I was wondering if anyone has any documentation on how the coder is encoded so that I might be able to get information that comes from IB myself.
Thanks.
EDIT
Reason for doing this: I would like the font name given in the xib file. Apple's implementation of initWithCoder disregards the font name given in the file if it's a custom font and when you go to access the label's font, it returns the system font. Therefore I'd like to catch the font name before the original initWithCoder ignores it.
Looking through the documentation, there does not appear to be a way to retrieve all the keys used in an NSKeyedArchiver. One way "around" this is to archive your custom UILabel to an NSData object, write the data object out to a file, and then pop it open in a text editor and see if you can find some of the keys that way.
What information do you need from the UILabel that you can't access through its normal accessors?
If you look at the nib file compiled from the xib file for the interface you wanna decode, you'll be able to make out some of the keys you can use. It's kind of hard to find stuff, but it's better than nothing.

modifying plist file

i want to modify entries in custom plist file programmatically.
can anybosy suggest me a way to do that? i have tried modifying values of keys but file is not getting saved..
You don't provide much information as to what you've tried, but I assume from the tag that this is on the iPhone. In addition to Pat's suggestion, make sure that the plist you are trying to edit is not within your app bundle, but located within an editable location like Documents or Library within your sandbox.
I would look at the NSDictionary method:
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
I'm sure there's a similar method for NSArray.