程序员

Bridge的用法

2016-12-14  本文已影响0人  小布衫

1 _ _bridge

    CFStringRef cfString = CFStringCreateWithCString(NULL, "string", kCFStringEncodingUTF8);
    NSString *string = (__bridge NSString *)cfString;
    //需要手动释放
    CFRelease(cfstring);
    NSString *string = @"string";
    CFStringRef cfString = (__bridge CFStringRef)string;
    //无需手动释放

2 _ _bridge_retained/CFBridgingRetain

    NSString *string = @"string";
    CFStringRef cfString = (__bridge_retained CFStringRef)string;
    //需要手动释放
    CFRelease(cfString);
    NSString *string = @"string";
    CFStringRef cfString = CFBridgingRetain(string);
    //需要手动释放
    CFRelease(cfString);

3 _ _bridge_transfer/CFBridgingRelease

    CFStringRef cfstring = CFStringCreateWithCString(NULL, "string", kCFStringEncodingUTF8);
    NSString *string = (__bridge_transfer NSString *)cfstring;
    //无需手动释放
     CFStringRef cfstring = CFStringCreateWithCString(NULL, "string", kCFStringEncodingUTF8);
    NSString *string = CFBridgingRelease(cfstring);
    //无需手动释放
上一篇下一篇

猜你喜欢

热点阅读