Re: cannot be sent to an abstract object of class
Re: cannot be sent to an abstract object of class
- Subject: Re: cannot be sent to an abstract object of class
- From: "Stephen J. Butler" <email@hidden>
- Date: Sat, 4 Dec 2010 17:56:48 -0600
On Sat, Dec 4, 2010 at 5:17 PM, Shane
<email@hidden> wrote:
> @interface
> {
> NSNumber *rate;
> // ...
> }
> // ...
> #end
>
> - (id) init
> {
> // …
> rate = [[NSNumber alloc] initWithFloat:0.0];
> // now has retain count of 1
> }
>
> - (void) myMethod
> {
> // ...
> [rate initWithFloat:[[config rate] floatValue]];
> // …
> }
>
> *** initialization method -initWithFloat: cannot be sent to an
> abstract object of class NSCFNumber: Create a concrete instance!
alloc and init* must come as a pair, and only once. You can't call any
init* method on an object a second/third/etc time.
More to the point, NSNumber is an immutable class. If you want to
change the value, you have to alloc/init another one. There are a
bunch of immutable Foundation classes: NSArray, NSDictionary,
NSString, etc.
_______________________________________________
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