Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve preview API #1

Merged
merged 16 commits into from
Mar 8, 2024
Merged

Improve preview API #1

merged 16 commits into from
Mar 8, 2024

Conversation

0xLeif
Copy link
Owner

@0xLeif 0xLeif commented Mar 8, 2024

  • Added new Application.preview to be used in #Preview to override the needed dependencies for the content view.
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()
    }
}

Mirror change of https://github.com/0xLeif/AppState/pull/98/files

@0xLeif 0xLeif added the enhancement New feature or request label Mar 8, 2024
@0xLeif 0xLeif merged commit 84b73f2 into main Mar 8, 2024
3 checks passed
@0xLeif 0xLeif deleted the leif/preview-improvements branch March 8, 2024 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant