My coredata components are like
and
My code For Upload And Fetch Data
i'm facing problem while getting image from coredata as image is showing upside down while setting up in screen.
while uploading it's perfect as it is.
i'm using CoreData default , with manual class generating method.
@NSManaged public var id: UUID?
@NSManaged public var title: String?
@NSManaged public var desc: String?
@NSManaged public var img: Data?
@NSManaged public var time: Date?
@NSManaged public var audio: Data?
let context = (UIApplication.shared.delegate as!
AppDelegate).persistentContainer.viewContext
func GetSimpleNotes() -> [Notes] {
let arrList = [Notes]()
do {
let catchdata = try context.fetch(Notes.fetchRequest())as! [Notes]
return catchdata
} catch {
print(error.localizedDescription)
}
return arrList
}
//MARK: Add PicPin
func AddSimpleNote(title: String, description: String, images: UIImage?, audio: URL?, completion: @escaping (String) -> Void) {
let newNote = Notes(context: context)
newNote.setValue(UUID(), forKey: "id")
newNote.setValue(title, forKey: "title")
newNote.setValue(description, forKey: "desc")
newNote.setValue(images?.pngData(), forKey: "img")
newNote.setValue(Date(), forKey: "time")
if let audio = audio, let audioData = try? Data(contentsOf: audio) {
newNote.setValue(audioData, forKey: "audio")
}
do {
try context.save()
completion("Note Added Successfully.")
} catch {
completion("Note Add Fail.")
}
}