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
Post a Comment