Coder221
Coder221

Reputation: 1433

Append string while saving it to attribute and remove while calling it

I like to add "abc" to eventTextField.text and save it to the attributeeventName below

eventInformation.setValue(eventTextField.text, forKey: "eventName")

I tried this

let abcString = "abc"
eventInformation.setValue(eventTextField.text?.append(abcString), forKey: "eventName")

but my app is crashing with following error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "eventName"; desired type = NSString; given type = _SwiftValue; value = ().'

Upvotes: 0

Views: 58

Answers (1)

vadian
vadian

Reputation: 285079

The error occurs because append is mutating but does not return anything,
that's the _SwiftValue; value = () (Void)

You need an extra step:

let abcString = "abc"
eventTextField.text?.append(abcString)
eventInformation.setValue(eventTextField.text, forKey: "eventName")

Upvotes: 1

Related Questions