• 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: Weird Apple Sample code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird Apple Sample code


  • Subject: Re: Weird Apple Sample code
  • From: Ruotger Skupin <email@hidden>
  • Date: Thu, 13 Dec 2007 15:03:07 +0100

Hi,

after some debugging I understood what goes on. (Teaches me not to shoot so fast ;-) )

The init method should look like this:

- (id) init {
	if(![super init]) // init my super class
		return nil;

	connClass = [HTTPConnection class]; // get the Class
	return self;
}


since -[HTTPServer init] does not return an HTTPConnection object as I thought -[HTTPConnection init] refusing to return something else than nil makes sense.


Sorry to bother you, though my last original question still holds.

Roddi

P.S.: Before complaining that I don't do self = [super init] read this: http://www.wilshipley.com/blog/2005/07/self-stupid-init.html


Am 13.12.2007 um 13:38 schrieb Ruotger Skupin:

Hi,

I stumpled over weird Apple sample code. It is in the CocoaHTTPServer example project (file: HTTPServer.m:7) of an Xcode 3 installation. Can someone give an explanation what this is doing?

@implementation HTTPServer

- (id)init {
   connClass = [HTTPConnection self];
   return self;
}

....

Obviously not returning the class you ask for is evil IMHO , but I could live with it if I understood the rest of that method. There's more (line 56):

@implementation HTTPConnection

- (id)init {
   [self dealloc];
   return nil;
}

....

The sample code doesn't seem to work anyway, so maybe someone just committed a broken edit to the repository?

Another question is: Should Apple really publish example code that looks like this?

Roddi

_______________________________________________

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

_______________________________________________

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


References: 
 >Weird Apple Sample code (From: Ruotger Skupin <email@hidden>)

  • Prev by Date: NSViewControllerArray?
  • Next by Date: Re: Weird Apple Sample code
  • Previous by thread: Re: Weird Apple Sample code
  • Next by thread: Re: Weird Apple Sample code
  • Index(es):
    • Date
    • Thread