I am trying to set the title of my notes using the first line from a UITextView. Only the last section of my code does not work.
(If you are wondering why I use "else" in addition to the 30-character expression, because if I do not put a note with at least 30 characters, there is an error)
override func viewWillDisappear(animated: Bool) { detailItem!.noteText = self.textView.text if !self.textView.text.isEmpty { var textViewString:String = self.textView.text if let range = self.textView.text.rangeOfString("\n") { let rangeOfString = self.textView.text.startIndex ..< range.endIndex let firstLine = self.textView.text.substringWithRange(rangeOfString) detailItem?.noteTitle = firstLine } else {
So a code that doesn't work is the last part:
} else { let firstLine = (textView.text as NSString).substringFromIndex(length) detailItem?.noteTitle = firstLine }
Questions:
1) What is the difference between plain old int and variable, what is int?
2) What is the work to achieve the same result if my method is not possible?
source share