Is there any parallel in Objective-C to C#'s y

2019-06-19 22:20发布

问题:

This question already has an answer here:

  • Is there anything in Objective-C similar to C# yield return 2 answers

The first time I saw the yield keyword in C# I thought "yuck what a way to junk up the language". Having grown since then and actually used the language I find it so pleasantly simple to express state logic that I'd like to use a similar approach in other development platforms.

I'm exploring Objective-C for some support utilities. Is there anything like the C# yield keyword for Objective-C?

回答1:

There's no real support for it in the language as far as I know, but here's an implementation someone took the time to build, might be helpful.



回答2:

the NSThread is a wrapper over pthread (according to the documentation) conceptually if all you need is really to yield the thread, you can use pthread_yield().