# Debugging Core-Data and Swift UI

**URL:** <https://forums.kodeco.com/t/debugging-core-data-and-swift-ui/129019>\
**Category:** Core Data by Tutorials\
**Created:** [January 1, 2021, 3:57pm UTC](https://forums.kodeco.com/t/debugging-core-data-and-swift-ui/129019 "2021-01-01T15:57:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![theapapp](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/theapapp/32/93558_2.png) [@theapapp](https://forums.kodeco.com/u/theapapp)\
**Post date:** [January 1, 2021, 3:57pm UTC](https://forums.kodeco.com/t/debugging-core-data-and-swift-ui/129019/1 "2021-01-01T15:57:18Z")

</div>

I have written a new Core-Data app with a Header and Detail record. It was working fine until I added a Transformer. Now the App shuts down on launch, closing the debugger in Xcode when it does this, and previews are not working - giving me the error - Error Domain=FBProcessExit Code=1 “The process exited voluntarily.” UserInfo={BSErrorCodeDescription=voluntary, NSLocalizedFailureReason=The process exited voluntarily.} on all views in the app. Can anyone help me figure out how to debug this?

I am including the model code and the transformer in case this helps:

```auto
import Foundation
import CoreData
import UIKit

extension Event {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<Event> {
        return NSFetchRequest<Event>(entityName: "Event")
    }

    @NSManaged public var cardFrontImage: UIImage?
    @NSManaged public var event: String?
    @NSManaged public var recipient: Recipient?

}

extension Event : Identifiable {

}

```

Tranformer code:

```auto
import Foundation
import UIKit

class ImageTransformer: ValueTransformer {
    
    override class func transformedValueClass() -> AnyClass {
        return NSData.self
    }
    
    override class func allowsReverseTransformation() -> Bool {
        return true
    }
    
    override func reverseTransformedValue(_ value: Any?) -> Any? {
        autoreleasepool{
            guard let data = value as? Data else {
                return nil
            }
            
            return UIImage(data: data)
        }
    }
    
    override func transformedValue(_ value: Any?) -> Any? {
        autoreleasepool{
            guard let image = value as? UIImage else {
                return nil
            }
            
            return image.jpegData(compressionQuality: 1.0)
        }
    }
}

```

and where I load the transformer:

```auto
@main
struct CardApp: App {
    @Environment(\.scenePhase) private var scenePhase
    let context = PersistentCloudKitContainer.persistentContainer.viewContext
    
    static let doInitialize: Void = {
        ValueTransformer.setValueTransformer(ImageTransformer(), forName: NSValueTransformerName("ImageTransformer"))
        // register transformers here
    }()
    
    static func main() {
        CardApp.doInitialize
    }
  var body: some Scene {
  // CODE
  }
 }

```

---

<div class="post-metadata">

**Author:** ![theapapp](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/theapapp/32/93558_2.png) [@theapapp](https://forums.kodeco.com/u/theapapp)\
**Post date:** [January 1, 2021, 5:52pm UTC](https://forums.kodeco.com/t/debugging-core-data-and-swift-ui/129019/2 "2021-01-01T17:52:37Z")

</div>

OK, I solved this, by moving the initialization of the ImageTransformer into my Persistent Initializer.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [June 17, 2021, 7:57am UTC](https://forums.kodeco.com/t/debugging-core-data-and-swift-ui/129019/3 "2021-06-17T07:57:20Z")

</div>

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