如果我尝试使用 dispatch_source_t 作为 NSMutableDictionary 中的键:
dispatch_source_t source = dispatch_source_create(stuff...);
NSMutableDictionary filesAndSources = [NSMutableDictionary dictionary];
filesAndSources[source] = @{stuff goes here};
我收到警告:
Sending 'dispatch_source_t' (aka 'NSObject<OS_dispatch_source> *') to parameter of incompatible type 'id<NSCopying> _Nonnull'
我认为这是因为 dispatch_source_t 不使用 NSCopying 协议。我的解决方案是将 dispatch_source_t 填充到 NSValue 中:
NSValue* val = [NSValue valueWithPointer:(__bridge const void* _Nullable)(source)];
filesAndSources[val] = @{stuff};
这可以消除警告,但我不确定这是否是传递 dispatch_source_t 的正确方法。