ios - 如何在 NSInvocationOpreation 中传递对象

标签 ios objective-c concurrency nsinvocationoperation

我创建了一个 NSInvocationOpertion 对象,如下所示

NSString *myString = @"Jai Hanuman";
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(taskMethod) object:myString];
NSOperationQueue *operatioQueue = [[NSOperationQueue alloc] init];
    [operatioQueue addOperation:operation];

谁能告诉我如何访问 taskMethod 中的 myString 对象?可能吗?

- (void)taskMethod{
    NSLog(@"Oh! Invocation's working buck");
}

最佳答案

你可以试试这个:

将您的方法更改为:

- (void)taskMethod:(NSString *) message{
NSLog(@"Oh! Invocation's working buck");
        message=//your string object;
  }

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(taskMethod:) object:myString];

关于ios - 如何在 NSInvocationOpreation 中传递对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730304/

相关文章:

iOS 自动布局 UILabel 包装

android - 如何通过 Google 标签管理器在 Intercom 中设置事件跟踪

ios - 如何唯一标识 iOS 设备而不是使用 UUID 和 UDID

ios - 如何找出SQLITE查询结果为NULL?

iOS 使用 NSBlockOperation 限制异步 API 调用

维护进程池的 Java 库

powershell - 如何将项目动态添加到 PowerShell ArrayList 并使用运行空间池递归处理它们?

ios - 通知触发时播放视频

objective-c - 使用 Quartz 2D 解析 pdf 时获取文本位置

java - 如何在 java 中一起提供 2 个变量的原子读/写?