• 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
Class clusters - infinite loop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Class clusters - infinite loop?


  • Subject: Class clusters - infinite loop?
  • From: Steve Canfield <email@hidden>
  • Date: Fri, 24 Jun 2005 23:08:54 -0700

This is a repost from what I just posted to comp.sys.mac.programmer.help, but I thought cross posting might be helpful.

I'm trying to create a class cluster.

First is my super class -- this is the init method

DataHolder.m
- (id)initWithData:(NSData *)someData {
    // look at the data
    if([someData length] > 100)  {
        self = [[BigDataHolder alloc] initWithData:someData];
    }
    else {
        self = [[SmallDataHolder alloc] initWithData:someData];
    }

    return self;
}

IE we chose the subclass based on the data... seems simple enough

Now onto the subclass's init methods

BigDataHolder.m //  basically same for SmallDataHolder
- (id)initWithData:(NSData *)someData {
    if(self = [super initWithData:someData]) {
        // do some initialization here, etc
    }
    return self;
}

Anyway, I think you can see the problem here. This is going to go into an infinite loop. What's the solution? Should I skip the call to super and just call super super's init? Should I class sniff in my DataHolder init? Is there some simple way out of this?

Class clusters seem cool but the documentation on how to actually implement them has been a little off so far.

Thanks in advance.
-Steve


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Class clusters - infinite loop?
      • From: Ondra Cada <email@hidden>
    • Re: Class clusters - infinite loop?
      • From: Ben Dougall <email@hidden>
    • Re: Class clusters - infinite loop?
      • From: email@hidden
    • Re: Class clusters - infinite loop?
      • From: Lee Morgan <email@hidden>
  • Prev by Date: Re: Why isn't my app showing up in launched applications
  • Next by Date: Can't keep from leaking memory
  • Previous by thread: Re: nibtool output
  • Next by thread: Re: Class clusters - infinite loop?
  • Index(es):
    • Date
    • Thread