When I first load my app, where are the assets for, say, images, located? Is it somewhere where loading them in the UI is never a performance issue and can always be done in the main thread? (e.g. even if there were 100 assets loaded at once)
I’m assuming it’s safe to load assets from asset catalog in main thread but I want to double check and also learn more.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
The signature of the StateObject initializer is init(wrappedValue thunk: @autoclosure @escaping () -> ObjectType). The fact that the autoclosure is marked as escaping intrigues me, because that suggests that it could be called after the init has returned.
Why this is interesting is because I have some code where the viewmodel given to the @StateObject depends on an implicitly unwrapped optional type, and I expect the top level initialization of the StateObject to crash because the implicitly unwrapped optional is not ready yet, but to my surprise it did not. My theory is that the autoclosure is being called after the View’s initialization had been called, when the dependency is ready.
heres a minimal sample of that.
class MyDependency: ObservableObject {
@Published var value = "Hello"
}
class MyViewModel: ObservableObject {
let dependency: MyDependency
init(dependency: MyDependency = TestApp.dependency) {
self.dependency = dependency
print("✅ ViewModel initialized with dependency:", dependency.value)
}
}
struct ContentView: View {
@StateObject private var viewModel = MyViewModel() // ⚠️ expected crash?
var body: some View {
Text(viewModel.dependency.value).onAppear { TestApp.dependency = Dependency()// dependency is set here after init has been called
}
}
}
@main
struct TestApp: App {
static var dependency: MyDependency! // not ready yet
var body: some Scene {
WindowGroup {
ContentView()
}
}```
It says that the APFS (Apple File System) is the default file system on iOS, but I just want to confirm that all Apple provided apps such as Photos, Notes, Keynote, Mail, use it also.
(hope this question isnt as ****** as it sounds, I guess I’m always a bit uncertain with Apple provided stuff as they have secret privileges)
For example, what if I wanted to remove CoreData from the SDK when I install to reduce the SDK’s size?