1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NSRange のループ

Posted at

マクロで書くならこんな感じ?
range の部分に関数コールなどを入れることはできない制限がある。

# define FOREACH_RANGE(range, i) \
    for (NSUInteger i = range.location; i < NSMaxRange(range); i++)

関数で書くならこんな感じ。
ただし break はできない。continue の代わりには return が使える。

static void each_range(NSRange range, void(^body)(NSUInteger index)) {
    for (NSUInteger i = range.location; i < NSMaxRange(range); i++) {
        body(i);
    }
}

関数の方が好みかな。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?