is there anything in Objective-C similar to C# yield return?
is there anything in Objective-C similar to C# yield return ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there is nothing in Objective-C that would let you built an iterable solution that easily.
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.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.