User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







objective-c:foundation.framework:nsnumber.h:numberwith

numberWith

+ (NSNumber *)numberWithChar:(char)value;
+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
+ (NSNumber *)numberWithShort:(short)value;
+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
+ (NSNumber *)numberWithInt:(int)value;
+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
+ (NSNumber *)numberWithLong:(long)value;
+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
+ (NSNumber *)numberWithLongLong:(long long)value;
+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
+ (NSNumber *)numberWithFloat:(float)value;
+ (NSNumber *)numberWithDouble:(double)value;
+ (NSNumber *)numberWithBool:(BOOL)value;
+ (NSNumber *)numberWithInteger:(NSInteger)value NS_AVAILABLE(10_5, 2_0);
+ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value NS_AVAILABLE(10_5, 2_0);
 

ObjC Sourcecode Example

    //** Sample Datatypes **
    int myInt = 30;
    double myDouble = 3.14;
    BOOL myBool = NO;
    float myFloat = 1.123456f;
 
    //************************ Creating NSNumber Objects *************************
 
    //** If you`re creating NSNumber objects like this, they will be autoreleased even without ARC! **
 
    NSNumber *myBoolNumberAutoreleased = [NSNumber numberWithBool:myBool];
    NSNumber *myIntNumberAutoreleased = [NSNumber numberWithInt:myInt];
    NSNumber *myDoubleNumberAutoreleased = [NSNumber numberWithDouble:myDouble];
    NSNumber *myFloatNumberAutoreleased = [NSNumber numberWithFloat:myFloat];
 
    NSLog(@"myBoolNumberAutoreleased: %@", myBoolNumberAutoreleased);
    NSLog(@"myIntNumberAutoreleased: %@", myIntNumberAutoreleased);
    NSLog(@"myDoubleNumberAutoreleased: %@", myDoubleNumberAutoreleased);
    NSLog(@"myFloatNumberAutoreleased: %@", myFloatNumberAutoreleased);
 

Output for this example code

2012-05-20 20:38:15.225 NSNumberSample[937:f803] myBoolNumberAutoreleased: 0
2012-05-20 20:38:15.228 NSNumberSample[937:f803] myIntNumberAutoreleased: 30
2012-05-20 20:38:15.228 NSNumberSample[937:f803] myDoubleNumberAutoreleased: 3.14
2012-05-20 20:38:15.229 NSNumberSample[937:f803] myFloatNumberAutoreleased: 1.123456

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
objective-c/foundation.framework/nsnumber.h/numberwith.txt · Last modified: 2024/02/16 01:12 (external edit)

Impressum Datenschutz