iOS NSInvocation
2016-02-24 16:21
381 查看
苹果文档:
An
an Objective-C message rendered static, that is, it is an action turned into an object.
are used to store and forward messages between objects and between applications, primarily by
and the distributed objects system.
An
contains all the elements of an Objective-C message: a target, a selector, arguments, and the return value. Each of these elements can be set directly, and the return value is set automatically when the
is dispatched.
An
can be repeatedly dispatched to different targets; its arguments can be modified between dispatch for varying results; even its selector can be changed to another with the same method signature (argument and return types). This flexibility makes
for repeating messages with many arguments and variations; rather than retyping a slightly different expression for each message, you modify the
as needed each time before dispatching it to a new target.
not support invocations of methods with either variable numbers of arguments or
You should use the
method to create
you should not create these objects using
This class does not retain the arguments for the contained invocation by default. If those objects might disappear between the time you create your instance of
the time you use it, you should explicitly retain the objects yourself or invoke the
to have the invocation object retain them itself.
An
NSInvocationis
an Objective-C message rendered static, that is, it is an action turned into an object.
NSInvocationobjects
are used to store and forward messages between objects and between applications, primarily by
NSTimerobjects
and the distributed objects system.
An
NSInvocationobject
contains all the elements of an Objective-C message: a target, a selector, arguments, and the return value. Each of these elements can be set directly, and the return value is set automatically when the
NSInvocationobject
is dispatched.
An
NSInvocationobject
can be repeatedly dispatched to different targets; its arguments can be modified between dispatch for varying results; even its selector can be changed to another with the same method signature (argument and return types). This flexibility makes
NSInvocationuseful
for repeating messages with many arguments and variations; rather than retyping a slightly different expression for each message, you modify the
NSInvocationobject
as needed each time before dispatching it to a new target.
NSInvocationdoes
not support invocations of methods with either variable numbers of arguments or
unionarguments.
You should use the
invocationWithMethodSignature:class
method to create
NSInvocationobjects;
you should not create these objects using
allocand
init.
This class does not retain the arguments for the contained invocation by default. If those objects might disappear between the time you create your instance of
NSInvocationand
the time you use it, you should explicitly retain the objects yourself or invoke the
retainArgumentsmethod
to have the invocation object retain them itself.
Getting the Method Signature
methodSignatureProperty
Creating NSInvocation Objects
+ invocationWithMethodSignature:
Configuring an Invocation Object
selectorProperty
targetProperty
- setArgument:atIndex:
- getArgument:atIndex:
argumentsRetainedProperty
- retainArguments 它会将传入的所有参数以及target都retain一遍。
- setReturnValue:
- getReturnValue:
Dispatching an Invocation
- invoke
- invokeWithTarget:
简单例子:
相关文章推荐
- iOS Code Signing的Invalid处理(根证书无效)
- iOS 编码复习(二)—— runtime
- iOS开发调试技巧总结
- Xcode7.1与iOS9之坑
- iOS 内购( IAP)处理流程
- APNS远程推送详细教程
- 浅谈iOS视频开发
- iOS Implicit declaration of function XXX is invalid in C99”
- iOS NSURLSession 详解
- ios 查询相册/摄像头/麦克风 的使用权限
- iOS 设计模式之外观模式 (Facade)
- iOS开发通知那些事
- 16年上传AppStore出现:Missing iOS Distribution signing
- iOS9开放的新API--Spotlight使用指南
- You don't have permission to access /nagios/ on this server
- iOS - 判断用户是否允许推送通知
- 适配ios设备集锦
- ios 系统地图
- iOS核心动画 Core Animation2-CABasicAnimation
- iOS 本地推送通知