本文介绍了在Objective-C中有什么类似于C#收益率回报的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Objective-C中有什么类似于C#yield return?

is there anything in Objective-C similar to C# yield return?

推荐答案

不,Objective-C中没有什么可以让您轻松构建可迭代的解决方案.

No, there is nothing in Objective-C that would let you built an iterable solution that easily.

通常, fast Objective-C中的枚举 是使用与C#,Java或C ++完全不同的机制构建的.采用该协议相对来说比较复杂,特别是与带有yield return的C#相比,尽管它肯定是可行的.

In general, fast enumeration in Objective-C is built using an entirely different mechanism from C#, Java, or C++. Adopting the protocol is relatively complex, especially compared to C# with its yield return, though it is certainly doable.

我发现,Objective-C块为快速枚举提供了一种有用的替代方法.考虑实现基于块的枚举而不是快速枚举-它使您可以使用类似于yield return的样式来编写自己的API.另一方面,API的客户端需要提供一个块才能使用您的枚举.这不是理想的方法,但是可以使用,尤其是对于复杂的枚举器,例如基于树的枚举器.

I found that Objective-C blocks provide a usable alternative to fast enumeration. Consider implementing a block-based enumeration instead of fast enumeration - it lets you program your own API using the style similar to yield return. On the flip side, the clients of your API would need to supply a block to use your enumeration. This is not ideal, but usable, especially for complex enumerators, such as ones based on trees.

这篇关于在Objective-C中有什么类似于C#收益率回报的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 17:12