はじめに この記事は、第5回スタートアップiOS勉強会 - connpassでの同名の発表を文章形式でリライトしたものです。 スライド版(Speaker Deck)はこちら。 String と NSString 「文字列の特定の単語に色をつけて、textViewに表示したい」 …という、ヒトなら誰しもが持つ欲望をさらけ出してください。 そう言われたあなたは、以下のようなコードを書くかもしれません。 func coloredText(from str: String, target: String) -> NSAttributedString { // 対象単語の出現範囲( Range<String.Index> )を取得 let range: Range<String.Index> = str.range(of: target)! // Range<String.Index> を NSRa