objective c - Getting CFMutableDictionaryRef Values -
i access values cfmutabledictionaryref , math on them. using code below have managed print properties of battery. able print out single values (although in doing warning:invalid receiver type:cfmutabledictionaryref).
then try convert string values nsnumber , program bugs. gives me unrecognized selector sent instance 0x5d65f70 help?
cfmutabledictionaryref matching , properties = null; io_registry_entry_t entry = 0; matching = ioservicematching( "iopmpowersource" ); //matching = ioservicenamematching( "applesmartbattery" ); entry = ioservicegetmatchingservice( kiomasterportdefault , matching ); ioregistryentrycreatecfproperties( entry , &properties , null , 0 ); nslog( @"%@" , properties ); nsstring * voltage = [properties objectforkey:@"voltage"]; nsstring * currentcapacity = [properties objectforkey:@"currentcapacity"]; nsnumberformatter * f = [[nsnumberformatter alloc] init]; [f setnumberstyle:nsnumberformatterdecimalstyle]; nsnumber * mynumber = [f numberfromstring:voltage]; [f release]; cfrelease( properties ); ioobjectrelease( entry );
i able print out single values (although in doing warning:invalid receiver type:cfmutabledictionaryref).
that's because compiler doesn't know cfmutabledictionaries nsmutabledictionaries. you'll have use explicit cast tell compiler sending messages dictionary ok. either that, or use cfdictionarygetvalue
instead (cfmutabledictionary subclass of cfdictionary).
then try convert string values nsnumber , program bugs. gives me unrecognized selector sent instance 0x5d65f70
it tell us:
- what selector wasn't recognized
- what kind of object 0x5d65f70 @ time
- what line of program caused exception (the debugger tell if run application under it)
at guess, might check whether object voltage key string logging object's class
. might number. it's reasonable assume expects nsstring try send nsstring messages whatever give it, if give nsnumber, you'll have sending nsstring messages nsnumber object, 1 possible cause of exception.
Comments
Post a Comment