in my swift code below the goal is to fetch a boolean value from core data. Once that value is fetched it should be filtered using a if statement. If the value is true is should display a image on the image view and if it is false it should display a different image. I am getting a error at if let imageData = info[imageNo].bool { stating Initializer for conditional binding must have Optional type, not 'Bool'. Don't know what to do next. I added a photo of my core data below
func getBool(imageNo:Int) {
// first check the array bounds
let info = helpBool.shareInstance.fetchBool()
print("image count is", info.count)
if info.count > imageNo {
// check if the data is available
//
if let imageData = info[imageNo].bool {
if true{
fetchImageView.image = UIImage(named: "true")
}
else {
fetchImageView.image = UIImage(named: "false")
}
}
//
}
}
func fetchBool() -> [OnOff] {
var fetchingImage = [OnOff]()
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "OnOff")
do {
fetchingImage = try context.fetch(fetchRequest) as! [OnOff]
} catch {
print("Error while fetching the image")
}
return fetchingImage
}
}