CHAPTER 7

image

Numbers

NSNumber

NSNumber is the class used in Objective-C to work with numbers. NSNumber gives you a way to turn floating point and integer values into object-oriented number objects. While you can’t use NSNumber objects in expressions, NSNumber objects become useful when complicated formatting is required.

NSNumber objects can be created with many different constructors, but the most common way you’ll see NSNumber objects created is with the @ symbol followed by a number.

NSNumber *num1 = @1;NSNumber *num2 = @2.25;

Sometimes you may want to use special constructors that are matched to numbers stored in a particular way.

NSNumber *num3 ...

Get Objective-C Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.