ios - Cast id to a long type crashes -


i'm trying cast id value, returned json, long value (timestamp purposes).

xcode sais me:

-[__nscfstring longvalue]: unrecognized selector sent instance 0x15d3f220 terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfstring longvalue]: unrecognized selector sent instance 0x15d3f220' 

the next lines break code.

long time_now = [self gettimestamp];                     long fdate = [[results2 objectforkey:@"pll_first_date"] longvalue];                     long sdate = [[results2 objectforkey:@"pll_second_date"] longvalue]; 

what i'm doing wrong? id type not dynamic type casted?

after comments, possible solution:

long long time_now = [self gettimestamp];                     long long fdate = [(nsstring *)[results2 objectforkey:@"pll_first_date"] longlongvalue];                     long long sdate = [(nsstring *)[results2 objectforkey:@"pll_second_date"] longlongvalue]; 

this isn't cast, it's method invocation. and, can't cast id long (well, could, has limited utility).

you're trying ask nsstring convert long, doesn't respond longvalue.

nsstring have longlongvalue method use instead.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -