If I have an array of data for instance:
let array = ["73", "24", "12", "62", "42"]
And I would like to loop through the array and add its number to my entity called Device with attribute asset_tag and then print out the values from my core data stack.
Currently my code is as follows:
var data: [String] = ["53","35","26","42","12"]
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let task = Device(context: context)
task.asset_tag = data
(UIApplication.shared.delegate as! AppDelegate).saveContext()
do {
data = try context.fetch(Device.fetchRequest())
}
catch {
print ("This did not work")
}
print (data)
but it doesn't look like you can just add an array as the source for data into an attribute.
[Any]?Device(context: context)is a custom method. I have no idea what it does exactly. Otherwise (pseudocode) :for tag in data { let device = create_the_device(); device.asset_tag = tag } save_the_context()