Swift 3 textview. How do you add \n to line breaks when return key is pressed

时间:2017-12-18 06:24:04

标签: ios swift3 textview uitextview alamofire

I created a form and in that form is a textview where user's can type to report problems with the app. The problem is when the user clicks the return key it creates a line break [Line 2. in the image]. The textview text is stored in the text variable and is being passed to a url. I already am using replaceOccurences for spacing in between words. How would add \n to the line breaks created by the return key?

Thanks.

enter image description here

I want the text stored in database to look like this:

This is where text goes. Line break below \n this is after the return key...

@IBAction func send(_ sender: AnyObject){

let text = textView.text!

if(text.isEmpty){ Alert01("Please provide a brief description."); return }

let reportUrl = "http://www.appurl.com/report.php?id=\(userId)&message=\(text)"

let urlEncodedString = reportUrl.replacingOccurrences(of: " ", with: "%20")

parseJSON(url: urlEncodedString) }

}

0 个答案:

没有答案