Casting a CFDictionaryRef to NSDictionary?

后端 未结 3 718
醉话见心
醉话见心 2020-12-16 09:10

I have the code (stripped down):

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


        
相关标签:
3条回答
  • 2020-12-16 09:39

    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.

    0 讨论(0)
  • 2020-12-16 09:39

    Try this code,

    NSDictionary *ssidList = (__bridge NSDictionary*)myDict;
    NSString *SSID = [ssidList valueForKey:@"SSID"];
    
    0 讨论(0)
  • 2020-12-16 10:03

    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);
    
    0 讨论(0)
提交回复
热议问题