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
here * * runtime error: Thread 1: "-[Attribute setImageD:]: unrecognized selector sent to instance 0x6000034aabc0"
attribute.order = 3 // 3 = image
attribute.item = item // parent record
return attribute
}
as requested... it creates new attribute object, initilises the field (oh but not imageD?) and saves...
class func createAttributeFor(item: Item, name: String, order: Int?) -> Attribute {
let attribute = Attribute.newAttribute()
attribute.name = name
attribute.order = Int32(order ?? 0)
attribute.item = item
//
CoreData.stack.save()
return attribute
}
Looking at my own entry here makes me wonder... there seem to be 3 possible error points
Is this the right way to get the data representation of an image? let image = UIImage(named: "BartSimpson"); let imagedata = image?.jpegData(compressionQuality: 1)
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 {
is this the right way to reference the data? attribute.imageD = imageData // attribute value
where I error runtime Thread 1: "-[Attribute setImageD:]: unrecognized selector sent to instance 0x6000034aabc0"
What am I doing wrong?
THANKS MARK