Objective-C中“单向无效"的用例? [英] Use-case of `oneway void` in Objective-C?

查看:66
本文介绍了Objective-C中“单向无效"的用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NSObject.h中发现了一个奇怪的关键字

I found a strange keyword in NSObject.h

- (oneway void)release;

我在网上搜索,发现它与异步消息传递有关,看起来与Erlang的消息传递相似.

I searched the web, and learned it relates to asynchronous message passing, which looks similar with Erlang's message passing.

看来这可以带来很多有趣的事情.该关键字有哪些好的用例?

It seems this can make many interesting things. What are some good use-cases of this keyword?

推荐答案

oneway与分布式对象API一起使用,该API允许在不同线程或应用程序之间使用Objective-C对象.它告诉系统在方法返回之前,它不应阻塞调用线程.没有它,即使方法的返回类型为void,调用方也将阻塞.显然,除了void之外,它永远不会与其他任何东西一起使用,因为这样做将意味着该方法返回某些内容,但调用者无法获取它.

oneway is used with the distributed objects API, which allows use of objective-c objects between different threads or applications. It tells the system that it should not block the calling thread until the method returns. Without it, the caller will block, even though the method's return type is void. Obviously, it is never used with anything other than void, as doing so would mean the method returns something, but the caller doesn't get it.

有关分布式对象的更多信息,请参见

For more on distributed objects, see Cocoa Conceptual DistrObjects.

这篇关于Objective-C中“单向无效"的用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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