I want to save an item in the second spot of a binary data core data attribute. The core data entity is named Pictucre and the attribute is named pic. My code right is based off of something that would append the item to the core data attribute. What I want to do is is save it at slot 2. If something is at slot 2 it just saves over it. I am getting a error at
CoredataHandler.shareInstance.saveImage(data: imageData1)
Value of type 'UIImage' has no subscripts
class ViewController: UIViewController,UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@objc func leftM(){
if let imageData = imagePlace.image {
CoredataHandler.shareInstance.saveImage(data: imageData[1])
}
}
class CoredataHandler : NSManagedObject {
static let shareInstance = CoredataHandler()
func saveImage(data: Data) {
let imageInstance = Pictucre(context: context)
imageInstance.pic = data
do {
try context.save()
} catch {
print(error.localizedDescription)
}
}
class CoredataHandler : NSManagedObject {
static let shareInstance = CoredataHandler()
func saveImage(data: Data) {
let imageInstance = Pictucre(context: context)
imageInstance.pic = data
do {
try context.save()
} catch {
print(error.localizedDescription)
}
}}