• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Non-document based saving
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Non-document based saving


  • Subject: Non-document based saving
  • From: "LANCE GREENWOOD" <email@hidden>
  • Date: Fri, 26 Sep 2003 10:05:43 -0600

I am building an application (not Document Based) and the window has two fields
I want to be able to type something into the two fields, save it, then load it.

What is on the screen:

One is an NSTextView and I pull out the unformated text using -string
the other field is an NSTextField
with two buttons one for "saving" the other for "loading"

Two variables are defined in the .h file as follows:

@interface myController : NSObject <NSCoding>

NSString *textFieldData;
NSString *newString;



My save method works, (I used HexEditor to see my data) and the save routine looks like this:

- (IBAction)saveAction:(id)sender
{
NSData *newData;

//Update the variable before saving
newString = [textViewOutlet string];
textFieldData = [textFieldOutlet stringValue];

//Now write it
newData = [NSArchiver archivedDataWithRootObject:self];

[newData writeToFile:@"/Users/lancegre/Desktop/Testfile" atomically:YES];

}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:textFieldData];
[coder encodeObject:newString];
}
- (id)initWithCoder:(NSCoder *)coder
{
textFieldData = [coder decodeObject];
newString = [coder decodeObject];
return self;
}

I tried to read it in like this and put the information on the screen:
- (IBAction)loadAction:(id)sender
{
self = [NSUnarchiver unarchiveObjectWithFile:@"/Users/lancegre/Desktop/Testfile"];

[textFieldOutlet setStringValue:textFieldData];
[textViewOutlet insertText:newString];

}
When I debug the program the debugger shows the variables set correctly except that it comes up as:
(self)->newString

So, the question is how do I load these two variables and display then in the two fields?

thanks Lance

_________________________________________________________________
Instant message with integrated webcam using MSN Messenger 6.0. Try it now FREE! http://msnmessenger-download.com
_______________________________________________
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.
  • Prev by Date: FYI: Crash bug in the Color Sampler sample on Apple's site
  • Next by Date: Re: NSTask taking control of my program
  • Previous by thread: Re: media support test, autostart and keyboard event
  • Next by thread: Passing arguments to an AppleScript?
  • Index(es):
    • Date
    • Thread