• 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
Why does initWithCoder has other self-object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why does initWithCoder has other self-object?


  • Subject: Why does initWithCoder has other self-object?
  • From: Arno Oesterheld <email@hidden>
  • Date: Wed, 17 Aug 2011 13:34:45 +0200

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Why does initWithCoder has other self-object?
      • From: Quincey Morris <email@hidden>
    • Re: Why does initWithCoder has other self-object?
      • From: Peter <email@hidden>
  • Prev by Date: RE: Problems with UIAlertView
  • Next by Date: Re: Why does initWithCoder has other self-object?
  • Previous by thread: Very different Document Saving in Lion, even without enabling asynchronous
  • Next by thread: Re: Why does initWithCoder has other self-object?
  • Index(es):
    • Date
    • Thread