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

前端 未结 2 1490
孤街浪徒
孤街浪徒 2021-01-14 08:22

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

2条回答
  •  离开以前
    2021-01-14 08:55

    There isn't directly and, as dasblinkenlight mentions, fast enumeration exists, but is quite a bit different.

    Mike Ash took this question on in 2009 and came up with an implementation of generators (similar concept):

    http://www.mikeash.com/pyblog/friday-qa-2009-10-30-generators-in-objective-c.html

    Pretty neat bit of runtime wizardry, but I wouldn't necessarily suggest adopting it simply because it enables design patterns that are quite alien to the underlying system; the maintenance and learning curve costs will be pretty steep for use in a production environment.

提交回复
热议问题