Post

Replies

Boosts

Views

Activity

Reply to Unit testing SwiftData
In my unit tests, I need to insert Foo into a context before I can set the relationship to Bar. If the parent entity does not have a context I see a crash in the getter. let foo = Foo(bar: []) container.mainContext.insert(foo) foo.append(bar: Bar(value: 0)) You will need to mark the test as running on the MainActor to access the mainContext.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’23
Reply to Swift test with CoreData in a Package
I think the problem you're having is because your package tests are in a different bundle. Packages define a separate test target in the Package.swift manifest. To allow your tests to access resources, like the momd file, you'll need to declare a public symbol for them. This is similar to what you would need to do to access those resources from your app target. For example, in a source file in your Swift package: public static let momURL = Bundle.module.url(forResource: "MyModel", withExtension: "momd") You can then use this to load the MOM in your unit tests: let mom = NSManagedObjectModel(contentsOf: momURL!)
Jul ’21
Reply to 'ID' is inaccessible due to '@_spi' protection level
I'm seeing the same issue. As a workaround I've manually added the conformance to Identifiable to the model: extension MyModel: Identifiable { public var id: PersistentIdentifier { persistentModelID } }
Replies
Boosts
Views
Activity
Sep ’23
Reply to Error in SwiftData migrationPlan execution
The only thing I see different to a migration I have working is that the versionIdentifier seems to have changed in Beta 5 to a non-optional string (the docs don't seem to have caught up). I've set them to a string of my choosing: static var versionIdentifier: String = "V1"
Replies
Boosts
Views
Activity
Jul ’23
Reply to Unit testing SwiftData
In my unit tests, I need to insert Foo into a context before I can set the relationship to Bar. If the parent entity does not have a context I see a crash in the getter. let foo = Foo(bar: []) container.mainContext.insert(foo) foo.append(bar: Bar(value: 0)) You will need to mark the test as running on the MainActor to access the mainContext.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’23
Reply to Scroll to Bottom of List in iOS 16 Beta / Xcode 14 Beta 3
I'm still seeing this in iOS 16.1 (FB11826112)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Bizarre CoreData error when moving to data model to swift package
It looks like your trying to load the model from the main bundle. You need to load it from the Swift package bundle and then pass it to the NSPersistentContainer initializer.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’22
Reply to Swift test with CoreData in a Package
I think the problem you're having is because your package tests are in a different bundle. Packages define a separate test target in the Package.swift manifest. To allow your tests to access resources, like the momd file, you'll need to declare a public symbol for them. This is similar to what you would need to do to access those resources from your app target. For example, in a source file in your Swift package: public static let momURL = Bundle.module.url(forResource: "MyModel", withExtension: "momd") You can then use this to load the MOM in your unit tests: let mom = NSManagedObjectModel(contentsOf: momURL!)
Replies
Boosts
Views
Activity
Jul ’21