将 CFDictionaryRef 转换为 NSDictionary?

发布于 2024-11-29 05:48:52 字数 438 浏览 1 评论 0原文

我有代码(精简):

CFDictionaryRef *currentListingRef;
//declare currentListingRef here
NSDictionary *currentListing;
currentListing = (NSDictionary *) currentListingRef;

然后我收到错误:

非 Objective-C 指针类型“CFDictionaryRef *”(又名“const”)的转换 ARC 不允许将 struct __CFDictionary **') 转换为 'NSDictionary *'

我做错了什么?如何从 CFDictionaryRef 转换为 NSDictionary

I have the code (stripped down):

CFDictionaryRef *currentListingRef;
//declare currentListingRef here
NSDictionary *currentListing;
currentListing = (NSDictionary *) currentListingRef;

And then I get the error:

Cast of a non-Objective-C pointer type 'CFDictionaryRef *' (aka 'const
struct __CFDictionary **') to 'NSDictionary *' is disallowed with ARC

What am I doing wrong? How do I convert from a CFDictionaryRef to an NSDictionary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

混吃等死 2024-12-06 05:48:52

ARC 改变了桥接的工作方式。

NSDictionary *original = [NSDictionary dictionaryWithObject:@"World" forKey:@"Hello"];
CFDictionaryRef dict = (__bridge CFDictionaryRef)original;
NSDictionary *andBack = (__bridge NSDictionary*)dict;
NSLog(@"%@", andBack);

ARC changed the way bridging works.

NSDictionary *original = [NSDictionary dictionaryWithObject:@"World" forKey:@"Hello"];
CFDictionaryRef dict = (__bridge CFDictionaryRef)original;
NSDictionary *andBack = (__bridge NSDictionary*)dict;
NSLog(@"%@", andBack);
不喜欢何必死缠烂打 2024-12-06 05:48:52

在 ARC 中,应该这样做:

CFDictionaryRef currentListingRef = ...;
NSDictionary *currentListing = CFBridgingRelease(currentListingRef);

这会释放 CF 对象并将该对象的所有权转移给 ARC
否则你应该手动释放CF对象。

In ARC, this should be done this way:

CFDictionaryRef currentListingRef = ...;
NSDictionary *currentListing = CFBridgingRelease(currentListingRef);

This releases the CF object and transfers ownership of the object to ARC
otherwise you should release CF object manually.

没︽人懂的悲伤 2024-12-06 05:48:52

试试这个代码,

NSDictionary *ssidList = (__bridge NSDictionary*)myDict;
NSString *SSID = [ssidList valueForKey:@"SSID"];

Try this code,

NSDictionary *ssidList = (__bridge NSDictionary*)myDict;
NSString *SSID = [ssidList valueForKey:@"SSID"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文