• 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: newbie question initWithCapacity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie question initWithCapacity


  • Subject: Re: newbie question initWithCapacity
  • From: Karl Kraft <email@hidden>
  • Date: Sat, 4 Jan 2003 20:30:52 -0600

On Saturday, January 4, 2003, at 08:05 PM, Joost Rekveld wrote:

and if I do a syntax check the compiler says there are multiple
declarations for 'initWithCapacity' and informs me it will use the
version found in NSString.h instead.

I can't begin to see how this can happen, how can a method of
NSString.h be used in a class which has no relation with it whatsoever ?


What type does allocWithZone: return?

Since JFRCurve is a subclass of NSObject, the implementation that will be used is this one:

+ (id)allocWithZone:(NSZone *)zone;

Type is id. Since the type is id, the compiler doesn't know that the returned object is a JFRCurve, and thus informs you that it is making a guess as to which implementation of initWithCapacity you mean. The compiler tends to guess poorly. I almost think it is on purpose.


Your Code:

+ (id)curveWithCapacity:(long)n {
return [[JFRCurve allocWithZone:[self zone]] initWithCapacity:n];
}

1) The allocWithZone probably doesn't do what you think it does. the [self zone] means whatever zone the JFRCurve class object was loaded into, which 99.99% of the time will be the default zone.

2) The object isn't autoreleased. Doesn't have to be, but methods with names like this one usually return autoreleased objects.

New Code (type into email, so it could be wrong):

+ (JFRCurve *)curveWithCapacity:(long)capacity;
{
JFRCurve *newCurve = [self alloc];
[newCurve initWithCapacity:capacity];
[newCurve autorelease];
return newCurve;
}



On Saturday, January 4, 2003, at 08:05 PM, Joost Rekveld wrote:

I can't begin to see how this can happen, how can a method of
NSString.h be used in a class which has no relation with it whatsoever ?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >newbie question initWithCapacity (From: Joost Rekveld <email@hidden>)

  • Prev by Date: Re: Checking OS Version with Cocoa
  • Next by Date: Re: How "Delete"_icon_as_a_menu_item_shortcut?
  • Previous by thread: newbie question initWithCapacity
  • Next by thread: Re: newbie question initWithCapacity
  • Index(es):
    • Date
    • Thread