Re: Text storage
Re: Text storage
- Subject: Re: Text storage
- From: David Remahl <email@hidden>
- Date: Mon, 11 Aug 2003 20:37:17 +0200
On Monday, August 11, 2003, at 8:01:58 PM, April Gendill wrote:
Just for the purpose of testing I am using the userdefaults because
they are easy. later the data storage will be in a plist in the main
bundle so I don't need advice on how using the preferences is a no no.
Actually, using the preferences is often a really good idea. Depending
on what data it is you will be storing. If the data will _change_ then
you shouldn't store it in the app bundle, since the user running the
application may not be privileged to write to the application bundle.
If, on the other hand, this is static data that only you (as the
developer) will change, then a plist in the app bundle is fine.
theNotes=[defaults objectForKey:@"0"];
//currently, the line for writing to the preferences is commented out
and it reads correctly. so this much is working.
- (NSAttributedString *) string { return theNotes; }
You have to retain (or even better, copy) the returned object from
objectForKey:, or it will be released before your accessor method is
called upon:
theNotes = [[defaults objectForKey:@"0"] copy];
at one point i tried these two methods:
- (void) setString: (NSAttributedString *) value {
theNotes=value;
NSLog(@"the Notes from Set string %@",theNotes);//this prints null
}
Change that to:
id oldNotes = theNotes;
theNotes = [value copy];
[oldNotes release];
- (NSAttributedString *) string { return theNotes; }
to maintain the data for theNotes.
there was no success.
trying to NSLog theNotes was still null . NSLog(@"%@",[notes string]);
trying to declare [notes setString:theNotes]; or anything else does not
work. and if memory serves
[notes setString:@"Test"]; still fails to produce anything.
returned null. (notes having been declared at the top of the
applicationwillterminate method.
so... I can get data from the preferences or static assignment into the
text view.
HOW then do I get the data that is in the text view back into some kind
of variable that will save into the preferences, and ultimately, when
the structure of the application is finished, into a file in the main
bundle?
[[NSUserDefaults standardUserDefaults] setObject:someObj forKey:@"0"];
/ Rgds, David
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >Text storage (From: April Gendill <email@hidden>) |