LoginSignup
2
2

More than 5 years have passed since last update.

enumerateLinesUsingBlock: を使って複数行のテキストを一行単位に処理する

Last updated at Posted at 2014-02-19

背景

TextViewに入力された文字列を、一行単位かつ要素単位に分割して永続的に保管するためのメモ。
とりあえずは、複数行を一行単位に処理する手段を探していた。

解法

(void)enumerateLinesUsingBlock:(void (^)(NSString *line, BOOL *stop))blockを利用する。

詳細

ブロック内のlineを使って、行単位にやりたいことを記述する

    //テキスト情報は一行単位で要素に分解
    NSMutableArray *lines = [NSMutableArray array];
    [_todaysRecord.contents enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {
        [lines addObject:line];
    }];

参考リンク

2
2
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
2
2