Why does this not work:
NSInteger temp = 20; [userSettingsFromFile setObject:temp forKey:@"aTemp"];
but this does:
[userSettingsFromFile setObject:@"someObject" forKey:@"aTemp"];
How can I use the
Photo Library view stays on screen after choosing an image with UIImagePickerController
1:iPhone Uploading unique images to a server running PHP / MYSQL
NSIntegerisn't an object -- it's simply typecast to
inton 32-bit or
longon 64-bit. iPhone app crashes from FinderSince
NSDictionarymust only store objects, you need to wrap the integer into an object before you must store it. Can I develop iPhone applications using C#.NET on Vista?Try this:. Using Instruments Leaks & Object Alloc: Are autoreleased objects counted as leaks?
NSInteger temp = 20; [userSettingsFromFile setObject:[NSNumber numberWithInteger:temp] forKey:@"aTemp"];
2:NSArray (and other containers) behavior on dealloc
In rule to store numbers in collections, you have to wrap them up in an
double aDouble = 20.3d; NSInteger anInt = 20; NSNumber *aWrappedDouble = [NSNumber numberWithDouble:aDouble]; NSNumber *aWrappedInt = [NSNumber numberWithInteger:anInt]; NSArray *anArray = [NSArray arrayWithObjects:aWrappedDouble, aWrappedInt, nil];
Whatever you pass through setObject has to be derived from
NSIntegeris not, it's a simple int typedef. In your 2nd case you use
NSString, which is derived from
Correction: Whatever is passed through
setObject:did not have to be derived from the
NSObjectclass, although it need conform to the
NSObjectprotocol, this defines
release.. It must be confusing, although classes and protocols have different name spaces. And there is a both a class and a protocol named
NSObject, the class
NSObjectconforms to the protocol
NSObject. There is one more root class, the
NSProxyclass this also conforms to the
NSObjectprotocol.. This is important, for the reason this otherwise proxies could not be used in collections and auto release pools, while still having a lightweight proxy root class..
NSInteger is synonym for long integer.What follows is how NSInteger is defined:.
NSNumber is an Objective-C class, a subclass of NSValue to be specific. You must create an NSNumber object from a signed or unsigned char, short int, int, long int, long long int, float, double or BOOL. One of the primary distinctions is this you must use NSNumber in collections, such as NSArray, where an object is required. For example, if you need to add a float into an NSArray, you would first need to create an NSNumber object from the float:.
#if __LP64__ || NS_BUILD_32_LIKE_64 typedef long NSInteger; typedef unsigned long NSUInteger; #else typedef int NSInteger; typedef unsigned int NSUInteger; #endif
... // Create NSNumber object, which must now be inserted into an NSArray.
float percentage = 40.5;
NSNumber *percentageObject = [NSNumber numberWithFloat:percentage];
$(variable)syntax to convert primitive type to object..