Skip to content

janodevorg/CoreDataStack

Repository files navigation

Source code for the article A Minimal Core Data Stack.

Testing

To test from the console use xcodebuild:

# test all
xcodebuild test -scheme CoreDataStack -destination 'platform=macOS' | xcbeautify

# test a particular function
xcodebuild test -scheme CoreDataStack -destination 'platform=macOS' -only-testing:CoreDataStackTests/EntityQueryTests/testAllQuery | xcbeautify

swift test won’t work because the model needs to be compiled to a momd file by xcodebuild. An alternative is to compile the momd using

xcrun momc Sources/Tests/Model.xcdatamodeld Model.momd

Then add it to resources in the package. Then the model would need to be loaded with

guard let modelURL = Bundle.module.url(forResource: "Model", withExtension: "momd"),
      let model = NSManagedObjectModel(contentsOf: modelURL) else {
    fatalError("Failed to load Core Data model")
}

Only Xcode compiles xcdatamodeld

You could compile from the terminal with

xcrun momc Sources/Persistence/Resources/Apuntika.xcdatamodeld Apuntika.momd

but the presence of this file would confuse xcode. By the way, it creats a momd if there are several Apuntika.xcdatamodel, like when you create versions. If there is only one, the extension is mom.

There is no clean way to load the model from the terminal. If tests seem to work check they are really running.

About

Minimal Core Data Stack

Resources

License

Stars

Watchers

Forks

Packages

No packages published