Chapter 6: ImageTransformer Issues v3 to v4

Working on chapter 6 and every time I run the code I keep getting the error message:

CoreData: warning: no NSValueTransformer with class name ‘ImageTransformer’ was found for attribute ‘image’ on entity ‘Attachment’

CoreData: warning: no NSValueTransformer with class name ‘ImageTransformer’ was found for attribute ‘image’ on entity ‘Attachment’

CoreData: warning: no NSValueTransformer with class name ‘ImageTransformer’ was found for attribute ‘image’ on entity ‘ImageAttachment’

I have the type set to Transformable and have checked every other thing I can think of. This showed up when I tried to build v4 out of v3. What would cause this to break?

Are you able to run migration from v3 to v4?
Mine is not able to run even.

No, it crashes before you even get there. I saw yours had to do with Codegen but I had already selected None/Manual. After I read your earlier issue I double or triple checked that.

turning on exception breakpoint. I bet our latest problem is the same.
and you are also crashing here
if let error = error {
fatalError(“Unresolved error (error)”) // <— crash here
}

see my this post. Error in migration from v3 to v4 (Custom migration Policy) - #2 by shogunkaramazov

It seems there might be something wrong.

@briandomanski @alokc83 Please check out the updated version of the book:

https://store.raywenderlich.com/products/core-data-by-tutorials

I hope it helps!

I’m had similar issues with the ImageTransformer using Xcode 12 beta 3 with version 3 using an iOS 14 simulator in chapter 6. I initially thought it was my code / core data doing something I didn’t want but it also happens on the downloaded resources. And after writing up some long post with some conjectures about the issue, I discovered that the issue is that ImageTransformer’s Objective-C name is not ImageTransformer. I changed line 31 of ImageTransformer.swift from

class ImageTransformer: ValueTransformer {

to

@objc(ImageTransformer)
class ImageTransformer: ValueTransformer {

and both my issues disappeared. I tested this solution with the download resources for the latest version of the book (7.0.0 at the time of writing) and the

CoreData: warning: no NSValueTransformer with class name 'ImageTransformer' was found for attribute 'image' on entity 'Attachment'

warning and the

'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release

warning went away.

To test with the download resources:

  1. Open 06-06-versioning-and-migration/starter/UnCloudNotes.xcodeproj
  2. Build and run the app
  3. Add some notes with titles (not necessary for the titles but helps verify you are using the same core data stack)
  4. Open 06-06-versioning-and-migration/v2/UnCloudNotes.xcodeproj
  5. Build and run the app
  6. Tap the back button
    • Expected Behaviour: No warnings in the console
    • Current Behaviour: There are warnings indicating not NSValueTransformer class named ImageTransformer
    • Note: This warning only happens during migration so you only get one shot or you have to restart these steps
  7. Add a note with an image
    • Expected Behaviour: No warnings in the console
    • Current Behaviour: There are warnings about NSKeyedUnarchiveFromData
    • Note: These warnings occur every time you load the table of notes and occurs for each note that has a photo.
  8. Repeat Steps 4, 5, 6, 7 for v3 and v4
    • You have the same behaviours

If you repeat these steps but add @objc(ImageTransformer) to ImageTransformer.swift before the build and run step, the expected behaviour and current behaviour should match.

2 Likes

Thank you, I faced the same problem, adding the @objc(ImageTransformer) did solve it.

Can somebody explain why adding the line is necessary though?

Core Data is uses Objective-C under the hood. I believe the issue is caused because Swift changes the names of its types (mangles the names). As such Swift will name ImageTransformer into something like MangledNameForImageTransformer (the name is not what Swift will call it but it’s irrevelant). So when Objective-C is looking for ImageTransformer symbol it can’t find it. By specifying @objc(ImageTransformer) there is no mangled version of the name. So Objective-C will find it.

This topic was automatically closed after 166 days. New replies are no longer allowed.