コードのこの部分を迅速に書く方法3?私はノートアプリを構築していて、この部分は、これがあなたのためにトリックを行う必要がありswiftのcountElements 3
if countElements(item.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())) > 0
func textViewDidChange(textView: UITextView) {
//separate the body into multiple sections
let components = self.txtBody.text.componentsSeparatedByString("\n")
//reset the title to blank (in case there are no components with valid text)
self.navigationItem.title = ""
//loop through each item in the components array (each item is auto-detected as a String)
for item in components {
//if the number of letters in the item (AFTER getting rid of extra white space) is greater than 0...
if countElements(item.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())) > 0 {
//then set the title to the item itself, and break out of the for loop
self.navigationItem.title = item
break
}
}
}
これは**のコードコメントではありません。基本的にはSwiftコードを英語で書き直しました。しかし、我々はスウィフトを読む方法を知っています。私たちは、「コンポーネント内のアイテム」が何を意味するのかを知っています。私たちは、**スウィフトと英語で説明された**方法は必要ありません。我々が必要とするのは**なぜ**です。なぜあなたがしていることをやっているのですか?あなたの意図は?あなたは何を達成しようとしていますか? ** **はコメントのためのものです。 – Alexander
テキストバーの最初の行がナビゲーションバーのタイトルに表示されたかった –