LIst of all region format - iphone

i'm be able to retrieve the region format of the user, ad example it_IT with this code
[NSLocale currentLocale] objectForKey:NSLocaleIdentifier];
is it possible have the complete list of these identifier?
(it_IT, de_DE, de_AT,....)
Thanks

[NSLocale availableLocaleIdentifiers] is yet another way.
For testing, specifically to insure all date formats are handled properly in my UI, I rip through that array, set a NSDateFormatter to use that and test for every possible combination of date formatting in an automated way.
Interesting what you learn along the way as well when you see some date representations that break your assumptions about how some dates, day names, etc might be formatted.

Try with this:
Returns an array of NSString objects that represents all known legal ISO currency codes.
[NSLocale ISOCurrencyCodes];
Returns an array of NSString objects that represents all known legal country codes.
[NSLocal ISOCountryCodes];
Returns an array of NSString objects that represents all known legal ISO language codes.
[NSLocale ISOLanguageCodes];
All the info from:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSLocale_Class/Reference/Reference.html

Related

Comparing the Key before adding to NSDictionary

I am adding dates into dictionary as the key and the corresponding value as some text ,but I am converting the date into string ,before adding to a dictionary,I have written the below code
[dateNoteDict setValue:datestring forKey:notes.text];
but before adding to dictionary I want to make some date comparision such that ,if the date present in dictionary is greater than ,the nest date then ,I should add below in the dictionary and so..on..
But I am not understanding how to do that.
So friends,please help me out..
Regards
Ranjit
You should do the comparison before converting the dates into NSStrings.
Assuming you are using NSDate objects, you can use the compare method. Have a look at this answer from S.O about date comparison.
Set some particular date format while setting as key in your dictionary. You can use NSDateFormatter for this. Also convert new date in the same format and then use "compare" for date comparison.
Thanks

How to check date validation in iphone?

I want to add date into my database ..
and I want to add it in some specific format ..like dd/mm/yyyy
how to check the validation for it?
Like e-mail validation .. I want to check is it in specified format or not?
how to do this ?
1) What is the input method for your date?
If it is thru a UIDatePicker, you have nothing to do, the UIDatePicker will return a valid NSDate. I encourage you to manipulate NSDate objects and use UIDatePickers as date inputs especially to avoid the question of date validation.
If it is thru a text field, you can set the UITextField's inputView to an UIDatePicker and you won't have to bother about date validation either as you will obviously directly have a (parsed) NSDate that you can manipulate directly, being sure it is valid.
Then in either case, use NSDateFormatter to convert your NSDate (entered by the user thru UIDatePicker) to an NSString (to insert in your database).
2) If you have a plain text entered by the user thru the keyboard, and can't or don't want to use a UIDatePicker (even as the inputView of your UITextField), you can convert your NSString to an NSDate thru an NSDateFormatter to check if it returns a non-nil NSDate (meaning it is a valid date).
Note: You may also use NSRegularExpression or NSPredicate classes to check the format of your string... but you won't have the subtleties of NSDate validation (like checking that 31/02/2011 or 67/13/99 is invalid)

Printing the locale names

I want to know and print the locale names which I am changing on my device. Is there any way to print them. Printing a NSLocale object does not help.
Create an NSLocale for the language in which you want the words to appear, then use -displayNameForKey:value: on the NSLocale object to get the display name for the NSLocaleIdentifier key.
The documentation for this method has an example that shows you exactly what you're looking for.

How to get an string representation from an NSDecimal without any formatting?

For example, I have an NSDecimal myDecimal. Lets say it represents something like "-1234567.89"
How can I get a clean string representation of that decimal without any beautification / formatting? No localization? Floating point symbol = . and rest only numbers from 0 to 9, and eventually an - if it is negative? I need that string in strict technical manner. A number like 123456789876554432123456789.2231 should therefore not look like nice formatted "123,456,789,876,554,432,123,456,789.2231". You get the point right?
I don't want any formatting. I'm trying all day now to get that right but everything I find always has to do with formatting. So how'd you guys do that?
I don't believe there is such a thing as a "clean" string representation independent of specifying the locale. As many Europeans would point out, 123.45 should be written as 123,45 (using , instead of . for the decimal location). NSDecimalString() (which can be found in the Foundation Functions Reference) takes, as a second parameter a locale specification. If some locale uses the format you desire, pass that locale as the second parameter (see the Internationalization Guide for more info on locales).
Alternatively, you can use an NSNumberFormatter, which will give you more controll over the string representation.
For easy (localized) control use an NSNumberFormatter.
float number = 12.345;
NSString* numberString = [NSString stringWithFormat:#"%f", number];
That will give you consistent formatting regardless of the user's current locale.

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this
279498721.322872
I am using Objective C in an Iphone App. Does anyone know how to make this export out as a regular date whether it is all number like
2009-02-10 or anything legible?
Well, if you take the number 279498721.322872 and throw it into an NSDate object using +dateWithTimeIntervalSinceReferenceDate, you get (here in the MDT timezone): 2009-11-09 15:32:01 -0700, which was just under 4 hours ago. If that's the time you're expecting, then formatting it is as simple as using an NSDateFormatter.
However, the thing to notice is that sqlite (by default) stores dates as textual representations (unless you specify differently in the sql statement). So the real question here is "where are you getting that number from?"
echo date("Y-m-d",time(279498721.322872));
Thanks for the responses. The answer came from my Guru Alex Cone. He told me to use the following:
NSTimeInterval tempInterval = (NSTimeInterval)sqlite3_column_double(statement, 4);
The tempInterval variable can then be loaded into the the NSDate method.