Hello,

I am a beginner with Xcode and Objective-C and stuck with a quite simple thing 
for over two days now. I hope you can help me.

My Project is deployed for OS X 10.6, it uses Garbage Collection and I am using 
Xcode 4.0.1.

I made a multi document application starting with the template provided by 
Xcode. I just have one class as subclass of NSDocument.

For opening documents I use initWithCoder. The decoding mithin this method 
works fine - I get the values that were saved.
But these values are "lost" when I would like to use them in an other method 
(of the same class).

I assume that I make some mistakes with using the right comibation of init: / 
initWithCoder: / initWithContentsOfURL: etc.
The self-object does always have a different adress in the initWithCoder method 
then in the other methods.
I tried plenty of combinations of the above methods and even tried to call 
differend methods in the super class (NSDocument) within initWithCoder.


This is my header file:

#import<Cocoa/Cocoa.h>

@interface OptimiererZwoMultiDoc : NSDocument<NSCoding>  {
    __strong struct bildanalyse {
        float winkelo;
                ...
        float skalfak;    // Der Skalierungsfaktor, den dieses Bild erfahren muss 
damit es so gross ist wie das kleinste - Wert ist also immer<= 0
    };

    __strong struct bildanalyse *analyse;
    __strong int16_t anzahlanalysewerte;
        ...

@private
    NSTextView *ausgabe;
        ...
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void) prepareAnalyseDoc;
...

@property (assign) IBOutlet NSTextView *ausgabe;
@property __strong struct bildanalyse *analyse;
@property __strong int16_t anzahlanalysewerte;
@end



When I try this implementation:

#import "OptimiererZwoMultiDoc.h"

@implementation OptimiererZwoMultiDoc

@synthesize ausgabe;
@synthesize analyse;
@synthesize anzahlanalysewerte;
...


- (id)init
{
    self = [super init];
    NSLog(@"init self=%@",self);
    if (self) {
        ...
    }
    return self;
}


- (NSString *)windowNibName
{
    NSLog(@"windowNibName self=%@",self);
    return @"OptimiererZwoMultiDoc";
}


- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    NSLog(@"windowControllerDidLoadNib self=%@",self);
    [super windowControllerDidLoadNib:aController];
}


- (BOOL) readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError 
**)outError{
     NSLog(@"readFromData self=%@",self);
     [NSKeyedUnarchiver unarchiveObjectWithData: data];
     if (outError) {
         *outError = [NSError errorWithDomain:NSOSStatusErrorDomain 
code:unimpErr userInfo:NULL];
     }
     return YES;
}


- (id) initWithCoder: (NSCoder *) coder{
    struct bildanalyse tempAnalyse;

    NSLog(@"initWithCoder self=%@",self);
    anzahlanalysewerte = [coder decodeIntForKey:@"anzahlanalysewerte"];
    ....
    return self;
}

then I get this output:

init self=<OptimiererZwoMultiDoc: 0x2002955a0>
readFromData self=<OptimiererZwoMultiDoc: 0x2002955a0>
initWithCoder self=<OptimiererZwoMultiDoc: 0x20028f5e0>
windowNibName self=<OptimiererZwoMultiDoc: 0x2002955a0>
windowControllerDidLoadNib self=<OptimiererZwoMultiDoc: 0x2002955a0>

As you can see, the object self is different in initWithCoder. Why? What's 
wrong with my code?

Any advice is very welcome.

Thank you very much in advance!

Best regards
Arno


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to