Skip to content

Instantly share code, notes, and snippets.

@HassanElDesouky
Created August 28, 2019 07:21
Show Gist options
  • Save HassanElDesouky/98c9c67979dc74a077119c92150db121 to your computer and use it in GitHub Desktop.
Save HassanElDesouky/98c9c67979dc74a077119c92150db121 to your computer and use it in GitHub Desktop.
private func createList() {
let context = CoreDataManager.shared.persistentContainer.viewContext
let list = NSEntityDescription.insertNewObject(forEntityName: "List", into: context)
list.setValue(nameTextField.text, forKey: "name")
if let firstColor = firstColorData {
list.setValue(firstColor, forKey: "firstColor")
}
if let secondColor = secondColorData {
list.setValue(secondColor, forKey: "secondColor")
}
if let image = iconImage.image {
let imageData = image.jpegData(compressionQuality: 0.8)
list.setValue(imageData, forKey: "imageData")
iconCellView.image = UIImage(data: imageData!)
}
do {
try context.save()
dismiss(animated: true) {
self.delegate?.didAddList(list: list as! List)
}
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment