What is the class NSCFNumber in iOS 4.1?
Asked Answered
P

3

23

After successfully acquiring a picture from the iPhone camera on iOS 4.1, you can use the key

@"UIImagePickerControllerMediaMetadata"

to return information about the picture. One of the keys in that dictionary is

@"Orientation"

From my experimentation, Portrait and Upside down are 6 and 8 respectively, and the landscapes are 1 and 3. Look at this code:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSDictionary *metaData = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
    id orientation = [metaData objectForKey:@"Orientation"];
    NSLog(@"Class: %@",[orientation class]);

The NSLog says "Class: NSCFNumber"

I need to compare this object's value to determine how to proceed. Landscape is 1 or 3, portrait is 6 or 8. I'm not sure what to type orientation as or what to call on it. NSNumber and NSInteger always tells me I'm making integers from pointers without casts.

Thanks for your time!

Pieplant answered 5/12, 2010 at 2:39 Comment(1)
I've gone around myself and just used the -description method on orientation to get a NSString, then used -isEqualToString: to make my determination. But I'd still like to know the answer =)Pieplant
O
37

This is telling you that orientation is a instance of NSNumber. Technically, NSCFNumber is a private subclass of NSNumber, but that is an implementation detail which you don't have to worry about. To get the integer value you would call

[orientation integerValue]
Overarm answered 5/12, 2010 at 2:47 Comment(4)
Is it necessary to typecast to NSNumber*?Hunch
No, it is not. Wasn't thinking when I typed that. I'll remove it to avoid causing further confusion.Overarm
I hate when somebody says "it is implementation detail". It is like somebody put the "barrier" and says "You can't go further" stop! What if there are people who want to go further, event if this isn't particularly useful ?Bevatron
Then Apple changes an implementation detail and your code stops working...Wolfort
H
7

NSNumber is a class cluster. NSCFNumber is a concrete, "private" implementation of a class in that cluster. Just use the returned value like you would an NSNumber object.

Homocyclic answered 5/12, 2010 at 2:48 Comment(0)
L
0

Nowadays (2022) the method has changed the name, and you needed to cast it to NSNumber before you can use it, like this:

[((NSNumber *) orientation) intValue];

And if you want to print it on OutputConsole, you need to use %d instead of %@, e.g.:

NSLog (@"%d", [((NSNumber*)  orientation) intValue] );
Liew answered 6/12, 2022 at 3:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.