|
Hi! I'm new to this community, and this is my first post :) I am new to Swift and SwiftUI/SwiftData, but I have 25 years experience in programming coming from a PHP/TS/Go/Rust background. I'm working on a SwiftUI form for adding new hotels, where each hotel belongs to a specific category (e.g., big hotel, medium hotel, small hotel). Each category defines a default number of rooms, and for each room, I need to capture a description. The hotel category also has a boolean which allows or not the user to override the category number of rooms of an individual hotel. In my implementation, selecting a hotel category updates the form to include a text input field for the description of each room based on the category's default room count. This works well when the room count is directly tied to the hotel category. However, the form also allows users to manually adjust the number of rooms using a stepper, overriding the default count specified by the hotel category. It's at this point I encounter a challenge: when the number of rooms is increased via the stepper, I get an 'Index out of range' error accessing the array that holds the room descriptions. How can I dynamically resize this descriptions array to accommodate the manual adjustments to the number of rooms without encountering out-of-range errors? I am aware of the Also, am I doing this the right "SwiftUI" way, or is there a better way to do it ? Appreciate any guidance or solutions you might have! Attached is the code:
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.