SWIFTUI unrecognised sector runtime error, saving image data to core data field

I get this a runtime error

runtime error: Thread 1: "-[Attribute setImageD:]: unrecognized selector sent to instance 0x6000034aabc0"
when running my code. When assigning the field see * * *

Some background, this started in my project so I striped my code to the minimum but still get this error,

CORE DATA DEFINITION

  ______________________________
  extension Attribute {
    
    @nonobjc public class func fetchRequest() -> NSFetchRequest<Attribute> {
        return NSFetchRequest<Attribute>(entityName: "Attribute")
    }
    
    @NSManaged public var name: String
    @NSManaged public var order: Int32
    @NSManaged public var item: Item
    @NSManaged public var imageD: Data?
 
}
 
  
_____________________________
 
 IN THE CALLING CODE I GET THE IMAGE ND CONVERT TO DATA, PASSING IN TO THE SAVING ROUTINE


  let image = UIImage(named: "BartSimpson");
  let imagedata = image?.jpegData(compressionQuality: 1)
            
   
 = Attribute.createPhotoAttributeFor(item: item,
                                                  imageData: imagedata!)
 
            CoreData.stack.save()
 
_________________________
 HERE THE SAVING METHOD GETS A RUNTUME ERROR WHEN TYPING TO SET THE IMAGED FIELD USINNG THE IMAGEDATE... SEE ***


    class func createPhotoAttributeFor(item: Item, imageData: Data) -> Attribute {
        
        let attribute = Attribute.newAttribute()
   
        attribute.name = "image"
        attribute.imageD = imageData            // attribute value
 
  • * * runtime error: Thread 1: "-[Attribute setImageD:]: unrecognized selector sent to instance 0x6000034aabc0"

 
        attribute.order = 3                     // 3 = image
        attribute.item = item                   // parent record
 
        return attribute
    }

WHAT AM I DOING WRONG?

THANKS
MARK

Replies

Looking at my own entry here makes me wonder... there seem to be 3 possible error points

1) Is this the right way to get the data representation of an image?

let image = UIImage(named: "BartSimpson");
let imagedata = image?.jpegData(compressionQuality: 1)

2) is this the right way to pass the data to a function?

    = Attribute.createPhotoAttributeFor(item: item,
                                                  imageData: imagedata!)

where

class func createPhotoAttributeFor(item: Item, imageData: Data) -> Attribute {

3) is this the right way to reference the data?

attribute.imageD = imageData            // attribute value