NSInvocation和block有什么区别? [英] What's the difference between NSInvocation and block?

查看:104
本文介绍了NSInvocation和block有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我说阻止"时,我的意思是:

^(int a) {return a*a;};

此外,阻止仅受iOS4及更高版本支持.

这两者有什么区别?

NSInvocation是给对象的消息(使用选择器),带有可选参数,该消息可以稍后(或现在)在对象外部执行.当前上下文(当然要记住复制,保留或引用的内容,如果移动的话). NSInvocation的优点是您可以有选择地复制/准确引用您所需要的内容.

该块是一个秘密的局部函数定义,它可以捕获当前线程上下文的全部或全部.与NSInvocation相比,它还更易于配置,因为它会自动捕获,复制和保留线程(或作用域)本地上下文.类似于函数,块可以稍微增加二进制大小.如果从本地上下文中取出数据(例如,复制块时),则与NSInvocation相比,块可能需要更多的CPU时间和内存.

when i say block i mean:

^(int a) {return a*a;};

besides, block is only support by iOS4 and above.

What is the difference between these two?

解决方案

An NSInvocation is a message (using a selector) to an object, with optional parameters, which can be executed later (or now), and outside the current context (mind of course what you copy vs retain or reference if you move it). NSInvocation has the benefit that you can selectively copy/refer to exactly what you need.

The block is a secret local function definition, which is able to capture portions of the current thread's context, or altogether. It's also a little easier to configure than an NSInvocation because it automatically captures, copies, and retains the thread (or scope) local context. Blocks can increase your binary size slightly, similar to functions. If taken out of the local context (e.g. when you copy a block), blocks can require quite a bit more CPU time and memory - when compared to NSInvocation.

这篇关于NSInvocation和block有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆