• 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: "Clark Cox" <email@hidden>
  • Date: Thu, 13 Dec 2007 05:44:53 -0800

On Dec 13, 2007 4:38 AM, Ruotger Skupin <email@hidden> wrote:
> 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;
> }

It's simply setting the connClass to HTTPConnection, the first time
any instance of HTTPServer is created. If I were doing this, I'd
probably do in +initialize instead:

@implementation HTTPServer

+(void)initialize {
    connClass = [HTTPConnection 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.

They're not returning anything different than what was asked for.

> There's more (line 56):
>
> @implementation HTTPConnection
>
> - (id)init {
>      [self dealloc];
>      return nil;
> }
>

This ensures that HTTPConnection cannot be instantiated via
[[HTTPConnection alloc] init]. This requires clients of the class to
call the other initializer
(-initWithPeerAddress:inputStream:outputStream:forServer:)

> ....
>
> 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?

That said, this code does look a bit sloppy for my tastes. Please file a bug.

--
Clark S. Cox III
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: Weird Apple Sample code
  • Next by Date: NSViewControllerArray?
  • Previous by thread: Weird Apple Sample code
  • Next by thread: Re: Weird Apple Sample code
  • Index(es):
    • Date
    • Thread