【问题标题】:How can I get a reference to the NSOperationQueue from an NSOperation?如何从 NSOperation 获取对 NSOperationQueue 的引用?
【发布时间】:2012-08-13 15:00:00
【问题描述】:

有没有办法从同一个 nsoperation 中获取 nsoperation 所在的“父”操作队列?类似于 [self getCurrentOperationQueue]。

【问题讨论】:

  • Objective C 中的“getters”往往没有 Java 等中的“get”前缀。

标签: objective-c ios nsoperation nsoperationqueue


【解决方案1】:

您可以通过从正在运行的操作中调用适当命名的+[NSOperationQueue currentQueue] 来获取当前队列。

当前队列
返回启动当前的操作队列 操作。

+ (id)currentQueue

返回值
启动操作的操作队列,如果无法确定队列,则为 nil。

讨论
您可以在正在运行的操作中使用此方法 对象以获取对启动它的操作队列的引用。 从正在运行的操作的上下文之外调用此方法 通常会导致返回 nil。

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多