I am getting an error of Cannot assign value of type ‘String?’ to type ‘UIImage?’ at imagePlace.image = picture.pic. I want to fetch the 2 item saved as core data binary. I added an image of my core data.
func fetchImages() -> [Picture] {
var arrImages = [Picture]()
fetchRequest.returnsObjectsAsFaults = false
do {
arrImages = try context.fetch(fetchRequest) as? [Picture] ?? [Picture]()
print("Images while fetching from coreData: \(arrImages)") // this will print all objects saved in coreData in an array form.
} catch let error {
print("Could not fetch images: \(error.localizedDescription)")
}
return arrImages
}
var imagePlace = UIImageView()
var resultImages = [Picture]()
func fetchImagesFromCoreData() {
if let picture = DataBaseHelper.shareInstance.fetchImageBy(id: 1) {
print("one")
imagePlace.image = picture.pic
resultImages = [picture]
// pic.image = resultImages.self
} else {
print("two")
resultImages = []
}
// resultImages = DataBaseHelper.shareInstance.fetchImagesByID(id: 2) // this will give fetched images
}