I have a UITextView
in my Swift app in which users can input text. They can input text with as many line breaks as they like but I need to save the string with the newline command (\n
). How would I do this?
For example, my user inputs
Line 1
Line 2
Line 3
in the UITextView
. If I was to retrieve the string...
let string = textview.text!
this would return
"Line 1
Line 2
Line 3"
when I would like for it to return
"Line1\nLine2\nLine3"
How would I go about doing this? Can I use a form of replacingOccurrences(of:with:)
? I feel like I'm missing a fairly obvious solution...