1.15.0
What's Changed
- Added new
Application.preview
to be used in#Preview
to override the needed dependencies for the content view. (Leif/preview improvements by @0xLeif in #98)
class Service {
var title: String { "Live Service" }
}
class MockService: Service {
override var title: String { "Mock Service" }
}
extension Application {
var service: Dependency<Service> {
dependency(Service())
}
}
struct ContentView: View {
@AppDependency(\.service) private var service
var body: some View {
Text(service.title)
}
}
#Preview {
Application.preview(
Application.override(\.service, with: MockService()),
Application.override(\.userDefaults, with: UserDefaults())
) {
ContentView()
}
}
Full Changelog: 1.14.0...1.15.0