In my swift code I attempted to fetch core data string using a int. I have 2 classes my base class and my helper class. In my base class that is where the func attempting to fetch the string. That func has a error message at fetchImageTxt.text = String(data: imageData) stating Missing argument for parameter ‘encoding’ in call. Don’t know how to resolve it.
BASE CLASS
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
var fetchImageTxt = UITextField()
func getT(imageNo:Int) {
// first check the array bounds
let info = DataBaseHelper.shareInstance.fetchImage()
if info.count > imageNo {
// check if the data is available
if let imageData = info[imageNo].img {
fetchImageTxt.text = String(data: imageData)
} else {
// no data
print("data is empty")
}
} else {
// image number is greater than array bounds
print("you are asking out of bounds")
}
}
}
HELPER CLASS
class DataBaseHelper {
static let shareInstance = DataBaseHelper()
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
func fetchImage() -> [Info] {
var fetchingImage = [Info]()
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Info")
do {
fetchingImage = try context.fetch(fetchRequest) as! [Info]
} catch {
print("Error while fetching the image")
}
return fetchingImage
}
}