This article provides a brief overview of techniques that can be used in your mobile iOS application to keep it secure enough for the vast majority of cases.
Explore algorithms and data structure usage with the example of finding emojis for word or phrase visual explanation using a natural language framework.
The New Apple Observation framework has some limitations. Let's take a look at a way to keep a value type for the model and use the Observation framework in the Swift application.
How to integrate a Web Component into a Mobile (iOS) application and don't break a "Native" UX spirit. What should you look at to keep the app consistent.
Refactoring the default SwiftData + SwiftUI project example. Removing SwiftData from SwiftUI and replacing Environment with a vanilla Dependency Injection.
Hello, thanks for your comment. One of the points in the article is that you don't really need to use Environment to pass data through layers in the app. If you need to pass the whole ViewModel to several layers deeper in the view hierarchy, I would double-check if you planned your architecture in this part well enough. The ViewModel should be responsible only for the views it is connected with. When the view is complicated and you are splitting it into several views, you might have a case to pass the ViewModel one layer down (maybe it's better to think about separate view models or states for such cases as well), but you don't need Environment for it. In case you want to use Environment, there is no need to extend EnvironmentValues. All you need is to use the environmentObject function that takes ObservableObject as a parameter and you can have something like this:
```swift
final class ViewModel: ObservableObject { ... }
struct FirstView: View {
// You can have your viewModel injected through init or created here
...
var body: some View {
SecondView()
.environmentObject(viewModel) // <----- here you inject it
Comments
Oct 26, 2023 · Aleksei Pichukov
Hello, thanks for your comment. One of the points in the article is that you don't really need to use Environment to pass data through layers in the app. If you need to pass the whole ViewModel to several layers deeper in the view hierarchy, I would double-check if you planned your architecture in this part well enough. The ViewModel should be responsible only for the views it is connected with. When the view is complicated and you are splitting it into several views, you might have a case to pass the ViewModel one layer down (maybe it's better to think about separate view models or states for such cases as well), but you don't need Environment for it. In case you want to use Environment, there is no need to extend EnvironmentValues. All you need is to use the environmentObject function that takes ObservableObject as a parameter and you can have something like this:
```swift
final class ViewModel: ObservableObject { ... }
struct FirstView: View {
// You can have your viewModel injected through init or created here
...
var body: some View {
SecondView()
.environmentObject(viewModel) // <----- here you inject it
}
}
struct SecondView: View {
@EnvironmentObject var viewModel: ViewModel
...
}
```