ios - Using a variable property value for NSCalendarIdentifier return nil -


i'm trying init nscalendar value variable below:

nscalendar *calendar = [[nscalendar alloc] initwithcalendaridentifier:jam.calendertype]; 

but calendar returns nil

i know that:

nscalendar *calendar = [[nscalendar alloc] initwithcalendaridentifier:nscalendaridentifierislamic]; 

and:

nscalendar *calendar = [[nscalendar alloc] initwithcalendaridentifier:nscalendaridentifiergregorian]; 

both work fine want value jam.calendertype nsstring has value of @"nscalendaridentifierislamic" or @"nscalendaridentifiergregorian"

your problem comes way store calendar identifier in variable. when wrote @"nscalendaridentifierislamic" means string characters, , not string nscalendaridentifierislamic identifier points to.

so set variable jam.calendertype = nscalendaridentifierislamic; or jam.calendertype = nscalendaridentifiergregorian; , work fine.

another easy solution have been make calendertype bool or int , based on it's value chose nscalendaridentifierislamic or nscalendaridentifiergregorian in calendar init.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -