• 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
Re: Init with something....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Init with something....


  • Subject: Re: Init with something....
  • From: Sandro Noel <email@hidden>
  • Date: Sun, 10 Dec 2006 00:43:05 -0500

Daniel, thank you!

initWithFile is calling [self init] not [super init]
if ((self = [self init])) {

I am doing it backwards :S

Sandro Noel.

On 9-Dec-06, at 11:53 PM, Daniel Jalkut wrote:

Hi Sandro - what you're discovering on your own is exactly the phenomenon covered by Apple's documentation of the "designated initializer":

http://developer.apple.com/documentation/Cocoa/Conceptual/ CocoaFundamentals/CocoaObjects/chapter_3_section_6.html#//apple_ref/ doc/uid/TP40002974-CH4-SW3

It's OK for you to have more than one initializer (e.g. initWithFile:) but you generally have a single designated initializer through which all other initializers will call. In your case, "init" is the designated initializer, so any other initializers in your class will call through to it *instead* of super. The designated initializer is the point at which the superclass init is incorporated into the class.

Daniel

On Dec 9, 2006, at 10:29 PM, Sandro Noel wrote:

Greetings.

Another one,

when i create a class,
I override the init like this,...

- (id) init{
		if ((self = [super init])) {// superclass may return nil
			// do init code here.
		}
		return self;
}

but what if i want to init with a file's content,

I still want to call the init method, for my normal init code to run.
so would this be a good way of doing it ?
of am i over/miss doing it again ....

- (id) initWithFile:(NSString *) path{
		if ((self = [self init])) {
			[self loadFile:path];
		}
		return self;
}

again thank you and please forgive, if my questions seem very beginner type :)

Sandro Noel.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
sweater.com


This email sent to email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Init with something....
      • From: Shawn Erickson <email@hidden>
References: 
 >Init with something.... (From: Sandro Noel <email@hidden>)
 >Re: Init with something.... (From: Daniel Jalkut <email@hidden>)

  • Prev by Date: dragging into an NSImageView in a modal window
  • Next by Date: Re: Init with something....
  • Previous by thread: Re: Init with something....
  • Next by thread: Re: Init with something....
  • Index(es):
    • Date
    • Thread