User.bw User.bw - 28 days ago 7
Swift Question

Type mismatch issue while adding to coredata array

I have added the data in an alertview textfield to the object of coredata like so...

let category = Category(context: self.context)
category.alertTextFieldData = (alertController.textFields?.first?.text)!


But now I wanted to add this to a CoreData Array which I am trying to do like this...

self.people.append(category.alertTextFieldData!)


But when I do this, it gives the error..

'Cannot convert value of type 'String' to expected argument type 'Category''


where
Category
is the entity name.

So how can I solve this issue...?

Answer Source

Replace this line:

self.people.append(category)

From:

self.people.append(category.alertTextFieldData!)