ios - Objective-C block 参数类型推断

标签 ios objective-c objective-c-blocks

我在 -[NSItemProvider loadItemForTypeIdentifier:options:completionHandler:] 的文档中看到了以下段落:

An extension can specify an expected class for the item’s value in the completion handler block. An error is returned in the completion block’s error parameter if the returned item’s value class doesn’t match the specified class. An item provider can perform simple type conversions for the item specified in the block, such as from NSURL to NSData or NSFileWrapper, or from NSData to UIImage (in iOS) or NSImage (in OS X).

不是说曾经想要制作一个如此疯狂的 API,但现在我很好奇。运行时 block 类型推断如何工作?

最佳答案

显然这并不新鲜。已经回答了here .

基本上,您可以公开重新声明 block ABI 的私有(private)部分(请参阅 this struct definition )并使用它来创建 NSMethodSignature (请参阅 this line of code )。

关于ios - Objective-C block 参数类型推断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27383068/

相关文章:

ios - 当项目发生变化时,Xcode 如何编译文件?

objective-c - 如何在 xcode 的 NSString 中使用变量作为文件名?

objective-c - 我的第一个 block 实验给了我 EXC_BAD_ACCESS 我不知道为什么

objective-c - 是否可以将 block 定义为类的成员?

javascript - 如何防止钛合金 View 中的事件冒泡?

ios - Restkit 0.20 JSON 映射以及额外的离线数据

ios - iAd 实现后应用程序崩溃

ios - ios删除avaudioplayer循环延迟

iphone - 收到内存警告。等级=1

ios - 返回一个 dispatch_async 获取的变量