Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does NSNumber automatically cast strings?

When creating an SKStoreProductViewController, I pass a dictionary with a parameter for the store identifier. :

@{ SKStoreProductParameterITunesItemIdentifier : @010101010 };

This value is supposed to be an NSNumber (as it is above):

The value associated with this key is an instance of NSNumber, representing the iTunes identifier for the item you want the store to display when the view controller is presented.

But it works without complaint when I pass the value as a string:

@{ SKStoreProductParameterITunesItemIdentifier : @"010101010" };

What's going on here? Is NSNumber automatically creating the correct number type from the string that it's given? Is this occurring in the NSNumber or is StoreKit doing this?

like image 914
nevan king Avatar asked Dec 02 '13 17:12

nevan king


2 Answers

Actually, thinking about it...

Initially I thought they must be converting the NSString into an NSNumber before doing whatever they need to do to get the information you are looking for.

However, on second thought...

I would guess that StoreKit is using the value against SKStoreProductParameterITunesItemIdentifier in a string. In which case they would do something like...

NSString *someStringToGetTheResults = [NSString stringWithFormat:@"thisIsThePath...?storeKitID=%@", dictionary[SKStoreProductParameterITunesItemIdentifier]];

This will be the same whether you pass in @12345 or @"12345".

Possibly...

No real way to tell though.

like image 135
Fogmeister Avatar answered Dec 11 '22 13:12

Fogmeister


The docs say that the value stored in the SKStoreProductParameterITunesItemIdentifier key is supposed to be an NSNumber. Saving anything else in that key may work today, but may also stop working after any OS release, so don't do it.

As others have suggested, it's pretty likely that the store kit is fetching the value of the SKStoreProductParameterITunesItemIdentifier key, assuming it's an NSNumber, and sending it an integerValue method to get it's numeric value. You got lucky since NSNumber and NSString both have an integerValue method.

like image 38
Duncan C Avatar answered Dec 11 '22 13:12

Duncan C