Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Subtle differences in the implementation of the Foundation framework on iPhone and OSX



Hello there,

Thought I'll share a little observation I just made, and that cost me about
an hour to debug. This is in hope that, using my experience, you may check
for similar bugs.

Look at this piece of code:

///

 NSNumberFormatter * nf = [[[NSNumberFormatter alloc] init] autorelease];

 [nf setNumberStyle:NSNumberFormatterSpellOutStyle];

 NSNumber * result = [nf numberFromString:@" five"];

 NSLog(@"result: %@", result);

 ///

If you were to run it in 10.6, no problem, it will return 5. However on the
iPhone (or, at least, on the simulator) you'll get a beautiful (null). The
problem seems to be the space in the string in front of 'five'. Apparently
OSX implementation of NSNumberFormatter trims the string while iPhone
implementation doesn't. I noticed this because I have a project with two
targets, one for iPhone and one for OSX. My application kept returning
different results while using the same source until I found this tidbit. So
I trimmed whitespace and it's all great.

Also, are there other similar inconsistencies I should be aware of that any
of you know of?

Peace,
Thanks
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.