I came across a weird behaviour of SwiftUI's ForEach view.
I've noticed that ForEach always initialize its child view twice as
much according to its repetition. Normally when you render the view, its
init is called once. But if you put the view inside ForEach and loop it 4 times, the child view is initialized 8 times instead of 4.
Is this a desired behavour or am I missing something?
tested on: Xcode 14.0.1, iOS 16, simulator iPhone 13 Pro (with iOS 16)
I am grateful for any feedback!
struct ContentView: View {
var body: some View {
VStack {
// Note that ForEach is looped 4 times!
ForEach(0..<4, id: \.self) { _ in
CustomView() // -> this view is initialized 8 times instead of 4.
}
}
}
}
struct CustomView: View {
// custom initializer with print to check how many times this view is initialized in log output
init() {
print("CustomView initialized")
}
var body: some View {
Text("Some Custom View")
}
}
Post
Replies
Boosts
Views
Activity
The Statement
I have a SwiftUI app that uses CoreData and iCloud with NSPersistentCloudKitContainer prepared for beta testing via TestFlight.
The app utilizes iCloud solely as a private database for user data across different devices. The app doesn't use any public or shared database.
According to Apple's guidelines, deploying the development schema to production is necessary before submitting to the App Store:
Before you publish your app, you must deploy the development schema to the production environment to copy over its record types, fields, and indexes.
I am aware that once deployed to production, it's impossible to delete or modify any types or fields:
To prevent conflicts, you can’t delete record types or fields that are already in production. Every time you deploy the development schema, its additive changes merge into the production schema.
The Questions:
When is the appropriate time to deploy the schema to production?
Should it be done before beta testing via TestFlight, or is it sufficient to deploy it just before releasing the app on the App Store after beta testing?
If the schema needs to be deployed before beta testing, does that mean I won't be able to reset the schema if testers discover critical bugs related to the data model, and I'll be compelled to delete or modify any types or fields?
Thank you in advance for any responses!