 |
|
 |
|
Next: ssh keepalive on OSX
|
| Author |
Message |
External

Since: Mar 31, 2004 Posts: 39
|
(Msg. 1) Posted: Sat Dec 13, 2003 1:20 pm
Post subject: PRoblem with archiving Archived from groups: comp>sys>mac>programmer>misc (more info?)
|
|
|
Hallo,
I do not find my failure.
I have a cocoa-document-application.
When I open a saved document I get this error:
2003-12-11 14:26:37.442 fsRune[964] *** NSUnarchiver: inconsistency
between written and read data for object 0x3e3690
My MyDocument only contains a
RunController * runController;
The RunController does only contain
@interface RunController : NSObject <NSCoding> {
NSMutableArray * runs;
The runs are:
@interface Run : NSObject {
double length_of_pipe; //Streckenlaenge
double height; //höhenmeter
NSCalendarDate * date; //datum
NSString * comments; //kommentar
NSString * location; //ort
int maxPulse; //pulse
int minPulse;
int avgPulse;
int shoeIndex;
}
Quite easy I think.
Now the open and save-routines:
MyDocument:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSLog(@"MyDocumemt:dataRepresentationOfType, Runs:%d",
[runController count]);
[[tableView window] endEditingFor:nil];
return [NSArchiver archivedDataWithRootObject:runController];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
NSLog(@"MyDocumemt:loadDataRepresentation, Runs:%d", [runController
count]);
[runController release];
runController = [[NSUnarchiver unarchiveObjectWithData:data]
retain];
return YES;
}
The RunController loads and saves this way:
-(id)initWithCoder:(NSCoder*)coder
{
NSLog(@"RunController:initWithCoder, runs:%d", [runs count]);
if(self = [super init]) {
[runs release];
[runs initWithCoder:coder];
}
return self;
}
-(void)encodeWithCoder:(NSCoder*)coder
{
NSLog(@"RunController:encodeWithCoder, runs:%d", [runs count]);
[runs encodeWithCoder:coder];
}
Now the last part, the run:
-(id)initWithCoder:(NSCoder*)coder
{
NSLog(@"Run:initWithCoder");
if(self = [super init]) {
[coder decodeValueOfObjCType:@encode(double)
at:&length_of_pipe];
[coder decodeValueOfObjCType:@encode(double) at:&height];
[self setDate :[coder decodeObject]];
[self setComments:[coder decodeObject]];
[self setLocation:[coder decodeObject]];
[coder decodeValueOfObjCType:@encode(int) at:&maxPulse];
[coder decodeValueOfObjCType:@encode(int) at:&minPulse];
[coder decodeValueOfObjCType:@encode(int) at:&avgPulse];
[coder decodeValueOfObjCType:@encode(int) at:&shoeIndex];
}
return self;
}
-(void)encodeWithCoder:(NSCoder*)coder
{
NSLog(@"Run:encodeWithCoder");
[coder encodeValueOfObjCType:@encode(double) at:&length_of_pipe];
[coder encodeValueOfObjCType:@encode(double) at:&height];
[coder encodeObject:date];
[coder encodeObject:comments];
[coder encodeObject:location];
[coder encodeValueOfObjCType:@encode(int) at:&maxPulse];
[coder encodeValueOfObjCType:@encode(int) at:&minPulse];
[coder encodeValueOfObjCType:@encode(int) at:&avgPulse];
[coder encodeValueOfObjCType:@encode(int) at:&shoeIndex];
}
I logged what happens:
add one run:
2003-12-11 14:26:24.670 fsRune[964] RunController:addRun, count before:0
Saving:
2003-12-11 14:26:29.253 fsRune[964] MyDocumemt:dataRepresentationOfType,
Runs:1
2003-12-11 14:26:29.253 fsRune[964] RunController:encodeWithCoder,
runs:1
2003-12-11 14:26:29.254 fsRune[964] Run:encodeWithCoder
2003-12-11 14:26:29.254 fsRune[964] RunController:encodeWithCoder,
runs:1
2003-12-11 14:26:29.254 fsRune[964] Run:encodeWithCoder
Why there are two times the RunController:encodeWithCoder when I only
have one run in the NSMutableArray?
Okay, now loading:
2003-12-11 14:26:37.436 fsRune[964] MyDocumemt:loadDataRepresentation,
Runs:0
2003-12-11 14:26:37.439 fsRune[964] RunController:initWithCoder, runs:0
2003-12-11 14:26:37.442 fsRune[964] *** NSUnarchiver: inconsistency
between written and read data for object
0x3e3690
Thanks for any help and sorry for my english...
Bye. >> Stay informed about: PRoblem with archiving |
|
| Back to top |
|
 |  |
External

Since: Jun 23, 2003 Posts: 253
|
(Msg. 2) Posted: Sat Dec 13, 2003 1:37 pm
Post subject: Re: PRoblem with archiving [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <1g5whe8.1gjh5wa1w4vvj4N%robert@vermtech.de>,
robert RemoveThis @vermtech.de (Robert W. Kuhn) wrote:
> Hallo,
>
> I do not find my failure.
>
> I have a cocoa-document-application.
>
> When I open a saved document I get this error:
>
> 2003-12-11 14:26:37.442 fsRune[964] *** NSUnarchiver: inconsistency
> between written and read data for object 0x3e3690
[snip]
> -(id)initWithCoder:(NSCoder*)coder
> {
> NSLog(@"RunController:initWithCoder, runs:%d", [runs count]);
>
> if(self = [super init]) {
> [runs release];
> [runs initWithCoder:coder];
This is not correct. 'runs' is just an object, so you should decode it
the same way you decode your other objects. Replace the initWithCoder:
line with:
runs = [[coder decodeObject] retain];
> -(void)encodeWithCoder:(NSCoder*)coder
> {
> NSLog(@"RunController:encodeWithCoder, runs:%d", [runs count]);
>
> [runs encodeWithCoder:coder];
You have the same problem here. To encode an object, you must call
[coder encodeObject:runs].
You should never call initWithCoder: or encodeWithCoder: directly. The
archiver will do that for you.
The rest of your code looks ok to me. I think that if you fix these
problems then you should be fine.<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: PRoblem with archiving |
|
| Back to top |
|
 |  |
External

Since: Mar 31, 2004 Posts: 39
|
(Msg. 3) Posted: Sat Dec 13, 2003 4:48 pm
Post subject: Re: PRoblem with archiving [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Michael Ash <mail.DeleteThis@mikeash.com> wrote:
> > -(void)encodeWithCoder:(NSCoder*)coder
> > {
> > NSLog(@"RunController:encodeWithCoder, runs:%d", [runs count]);
> >
> > [runs encodeWithCoder:coder];
>
> You have the same problem here. To encode an object, you must call
> [coder encodeObject:runs].
>
> You should never call initWithCoder: or encodeWithCoder: directly. The
> archiver will do that for you.
>
> The rest of your code looks ok to me. I think that if you fix these
> problems then you should be fine.
Thanks a lot! This solved my problem.
Bye.<!-- ~MESSAGE_AFTER~ --> >> Stay informed about: PRoblem with archiving |
|
| Back to top |
|
 |  |
| Related Topics: | Problem with OS X /usr/bin/as - Passing the --version argument to /usr/bin/as in OS X causes it to hang: % /usr/bin/as --version Apple Computer, Inc. version cctools-498.obj~14, GNU assembler version 1.38 <hangs...> Is there a fix for this? I came across this when trying to co...
Facing problem on MAC OSX 10.3 - Hi all, I am using MAC OSX 10.3 OS. I installed my USB modem driver in 10.3. I made the driver in 10.1.x MAC OSX. This driver worked in 10.1.x,10.2.x series. i.e., The Driver,application made in 10.1.x is compatble with 10.1.x & 10.2.x series. When...
Problem with archiver (/usr/bin/ar) - I am having a strange problem with /usr/bin/ar on Mac-OSX 10.3.1. On a local filesystem on the Mac it works fine: [360spider:~/temp] epics% cc -c -o hello.o hello.c [360spider:~/temp] epics% ar -rc hello.a hello.o The archiver created hello.a with no..
Problem with Toolbar - Hello, I want to have it easy with the toolbar: - (NSToolbarItem *)toolbar:(NSToolbar *)tb itemForItemIdentifier:(NSString *)tbit willBeInsertedIntoToolbar:(BOOL)flag { NSToolbarItem *tbi; NSImage *image; NSString *path; ...
Tech problem - Hi, I am using a G3 Mac system 9.2. I am experiencing what I call slow motion typing once in a while. As I type the letters appear slowly on the screen. I am not even a fast typer and yet it takes forever for the computer to keep up with me. What may be.... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|