开发者

Getting values from a CFDictionary

开发者 https://www.devze.com 2023-01-06 12:20 出处:网络
I\'m trying to access the val开发者_如何学Goues from a CFDictionary. I\'ve started by implementing code suggested in this question:

I'm trying to access the val开发者_如何学Goues from a CFDictionary. I've started by implementing code suggested in this question:

 CFTypeRef r = IOPSCopyPowerSourcesInfo();
 CFArrayRef array = IOPSCopyPowerSourcesList(r);
 CFDictionaryRef powerDic = IOPSGetPowerSourceDescription(array, r);

I have looked at the documentation plus other posts, but it's a bit beyond me how to work it.

What I really need is some example code that takes the code I already have and uses it to print a string of, for example, "Current Capacity".


CFDictionaryRef is "toll free bridged" with NSDictionary. This means you can cast one to the other interchangeably. In other words:

...
NSDictionary * powerDic = (NSDictionary *)IOPSGetPowerSourceDescription(array, r);
NSString * aValue = [powerDic objectForKey:@"aKey"];

If (for some reason) you need to stay at the CoreFoundation level (which isn't unheard-of), you'd use something like CFDictionaryGetValue().

0

精彩评论

暂无评论...
验证码 换一张
取 消