Created
August 28, 2019 07:21
-
-
Save HassanElDesouky/98c9c67979dc74a077119c92150db121 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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