Cast of C pointer type ‘CFArrayRef‘ (aka ‘const struct __CFArray *‘) to Objective-C pointer type ‘NS

Cast of C pointer type 'CFArrayRef' (aka 'const struct __CFArray *') to Objective-C pointer type 'NSArray *' requires a bridged cast

iOS开发时,objective-c类型转换时报错
错误出现的代码for (NSString *mode in (NSArray *)allModes)CFArrayRef类型转NSArray报错,如下

CFRunLoopRef runLoop = CFRunLoopGetCurrent();
    CFArrayRef allModes = CFRunLoopCopyAllModes(runLoop);
    
    while (!dismissed){
        for (NSString *mode in (NSArray *)allModes){
            CFRunLoopRunInMode((CFStringRef)mode, 0.001, false);
        }
    }
    
    CFRelease(allModes);

正确的for (NSString *mode in (__bridge NSArray*)

CFRunLoopRef runLoop = CFRunLoopGetCurrent();
    CFArrayRef allModes = CFRunLoopCopyAllModes(runLoop);
    
    while (!dismissed){
        for (NSString *mode in (__bridge NSArray *)allModes){
            CFRunLoopRunInMode((CFStringRef)mode, 0.001, false);
        }
    }
    
    CFRelease(allModes);

你可能感兴趣的:(objective-c)