• 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: cannot be sent to an abstract object of class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cannot be sent to an abstract object of class


  • Subject: Re: cannot be sent to an abstract object of class
  • From: Dave DeLong <email@hidden>
  • Date: Sat, 04 Dec 2010 15:52:55 -0800

NSNumber, like pretty much all "core" types in Foundation, is an abstract class.  You never have an NSNumber. You usually have an NSCFNumber, sometimes an NSBigMutableNumber, etc.  (You also never have an NSArray, but usually an NSCFArray, etc)

As such, if you wanted a retained NSNumber, you must do:

rate = [[NSNumber numberWithFloat:0.0] retain];

To actually allocate an NSNumber instance is (as you have found out) incorrect.

Cheers,

Dave

On Dec 4, 2010, at 3:17 PM, Shane wrote:

> I get the error below when trying to assign a new value (compile
> error) to rate in myMethod. Why is this NSNumber considered abstract?
> I would like to give it a new value.
>
> @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!
> _______________________________________________
>
> 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

  • Follow-Ups:
    • Re: cannot be sent to an abstract object of class
      • From: Dave DeLong <email@hidden>
References: 
 >cannot be sent to an abstract object of class (From: Shane <email@hidden>)

  • Prev by Date: cannot be sent to an abstract object of class
  • Next by Date: Re: cannot be sent to an abstract object of class
  • Previous by thread: cannot be sent to an abstract object of class
  • Next by thread: Re: cannot be sent to an abstract object of class
  • Index(es):
    • Date
    • Thread