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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -