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.
Related
I am using MPMediaItem, and getting all songs from library.
My issue is, if i want to get only particular file which I want.
Anybody can know ?
MpMediaItem provides property like
MPMediaItemPropertyAlbumTitle
MPMediaItemPropertyArtist
MPMediaItemPropertyGenre
MPMediaItemPropertyComposer
MPMediaItemPropertyTitle
By using above properties you can identify the file which you want.
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.
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.
I'm new here but I'd like to learn very well iPhone SDK...
I'm making an iPhone app where I'd like to show a modalView controller at launch of my app... How can I do this?
In this modalView, I request some informations and the view must appear only when these informations aren't saved!
Anyone can help me?
P.S.: Sorry for my bad English but I'm Italian... :D Thanks!
First, try to avoid to use NSUserDefautls as it's not application specific and can cause troubles under some circumstances (see reference docs).
I'd suggest to save your app specific data to some plist file for which you can check for at app startup -(void) applicationDidFinishLoading: method of your app delegate class - and decide if your modal view should be shown or not.
Let's say you have application wide accessible
NSMutableDictionary instance where you store your
preferences. When app is about to quit i.e. - (void)
applicationWillTerminate: method of your app delegate, simply store content of that dictionary to plist somewhere under you app directory structure (Documents folder is a good choice). See NSDictionary reference on how to store/read plist files. It's pretty simple.
Typically, you check for your saved data and if it's not there, you assume that it is the first run.
Thus, you first need to decide how you are going to persist data:
User defaults (NSUserDefaults).
Store a file. Typically a property list (plist) in the Documents directory.
Core Data.
I'd like to use NSUserDefaults...
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.