0

NSMutableDictionary のキーとして dispatch_source_t を使用しようとすると:

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 を渡す正しい方法かどうかはわかりません。

4

2 に答える 2