Releases: 0xLeif/AppState
1.17.0
1.16.0
What's Changed
Now you can use the setup parameter to preform any operations you need before the Application starts consuming the cache and publishing changes. This is useful for loading default dependencies your custom application might use.
class SomeApplication: Application {
static func someFunction() { /* no-op */ }
required init(setup: (Application) -> Void = { _ in }) {
super.init { application in
application.load(dependency: \.icloudStore)
setup(application)
}
}
}
Full Changelog: 1.15.0...1.16.0
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
1.14.0
What's Changed
- Property wrapper
@AppState
now supports all types of state: FileState, StoredState, SyncState, SecureState, and State. - SecureState is now supported for Constant and Slice.
What's Changed
Full Changelog: 1.13.0...1.14.0
1.13.0
1.12.0
1.11.0
1.10.2
1.10.1
1.10.0
Introducing DependencySlices and DependencyConstants in AppState!
AppState is all about improving the management of your application's state. Now we are taking it a step further with two new features: DependencySlices and DependencyConstants!
These features are designed to enhance the usage of values from ObservableObject
dependencies, making it even easier to bind to a value.
For example, consider the following ViewModel:
class ViewModel: ObservableObject {
@Published var isShowingSheet: Bool = false
@Published var username: String?
}
extension Application {
var viewModel: Dependency<ViewModel> {
dependency(ViewModel())
}
}
In the past, you would have accessed your ViewModel like this, where you would need to add @Published
to any variables:
struct BasicViewModelAppState: View {
@ObservedDependency(\.viewModel) private var viewModel
var body: some View {
InnerView(username: $viewModel.username)
}
}
struct InnerView: View {
@Binding var username: String?
var body: some View {
Text("[\(username ?? "World")]")
.onTapGesture {
username = "Tap"
}
}
}
But with the new DependencySlice feature, you can now access your ViewModel without needing to add @Published
to any variables, and the SwiftUI views will still update:
class ViewModel: ObservableObject {
var isShowingSheet: Bool = false
var username: String?
}
extension Application {
var viewModel: Dependency<ViewModel> {
dependency(ViewModel())
}
}
struct BasicViewModelAppState: View {
@ObservedDependency(\.viewModel) private var viewModel
var body: some View {
InnerView()
}
}
struct InnerView: View {
@DependencySlice(\.viewModel, \.username) private var username
var body: some View {
Text("[\(username ?? "World")]")
.onTapGesture {
username = "Tap"
}
}
}
What's Changed
Full Changelog: 1.9.1...1.10.0