I am developing an app that has a textView in FirstViewController and a tableView in the SecondViewController. In the app user types in a string using a textView, which is then turned into an array with the press of a button (indicated by an IBAction buttonIsPressed) and transferred onto a tableView in the next view controller with the help of UserDefaults. Right now, I want the code to be able to append all of the strings into one array every time user types in a string in textView. I have tried every single method I found on the internet to append either strings or arrays into one array but none of them worked. I would really appreciate if some of you can help me out. Here is the code:
@IBAction func buttonIsPressed(_ sender: Any) {
var newitems = textField.text!.components(separatedBy: CharacterSet(charactersIn: ", []()\n.:"))
print(newitems)
if newitems.contains(""){
newitems.removeAll { $0 == ""}
UserDefaults.standard.set(newitems, forKey: "items")
print(newitems)
}else{
let newitems = textField.text!.components(separatedBy: CharacterSet(charactersIn: ", []()\n.:"))
UserDefaults.standard.set(newitems, forKey: "items")
}
textField.text = ""
}