I have a NSDictionary object get from server API. data is like this,
"filesize_mp3":"60488"
when I use following code to retrieve file size, app crashes. obj.filesize is in long type.
obj.filesize = [[dict objectForKey:@"filesize_mp3"] longValue],
lldb console,
2014-07-22 12:50:14.643 YouVoiceNews[2019:60b] -[__NSCFString longValue]: unrecognized selector sent to instance 0x9bf8e10 2014-07-22 12:50:14.644 YouVoiceNews[2019:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString longValue]: unrecognized selector sent to instance 0x9bf8e10'
but when I use
obj.filesize = (long)[dict objectForKey:@"filesize_mp3"];
everything is fine.
so my question is what's the differences between above 2 ways. why first one cause app crash?
Thanks in advance.
NSString
doesn't have a method namedlongValue
. See the docs forNSString
. – rmaddy