5_Objective-C Numbers

in order to save the basic data types like int, float, bool in object form Objective-C provides a range of methods to work with NSNumber

What is NSNumber

NSNumber is a subclass of NSValue that offers a value as any C scalar (numeric) type.

Methods to work with NSNumber

  • Creates and returns
  • Returns the receiver’s

Creates and returns

methods use to creates and returns  an NSNumber object containing a given value, treating it to some data type .

  • + (NSNumber *)numberWithBool:(BOOL)value
  • + (NSNumber *)numberWithChar:(char)value
  • + (NSNumber *)numberWithDouble:(double)value
  • + (NSNumber *)numberWithFloat:(float)value
  • + (NSNumber *)numberWithInt:(int)value
  • + (NSNumber *)numberWithInteger:(NSInteger)value

Returns the receiver’s

Returns the receiver’s value data type.

  • – (BOOL)boolValue
  • – (char)charValue
  • – (double)doubleValue
  • – (float)floatValue
  • – (NSInteger)integerValue
  • – (int)intValue
  • – (NSString *)stringValue

Example : using NSNumber which multiplies two numbers and returns the product.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s