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.
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 UIViewController in UIStackView
I suspect the problem you are having is that typically the parent view controller sets the size and position of the child view controller. You can have the child view controller communicate its preferred size to the parent by having it (the child) set its preferredContentSize. You then implement preferredContentSizeDidChange in the parent view controller to react to the change. So you might have an optional height constraint in the parent view controller that you update with the preferred content size of the child view.
Jun ’20
Reply to Auto Layout Struggles
You're probably going to need to provide some more details before anybody can help. Failing that you might try using the view debugger and examine each view in the stack view. It will highlight any views that might be ambiguous which may give you a clue to what you are missing.
Jun ’20