|
1. I've added a picker to let the user change the currency (it's a minor quibble) but the currency symbol in the amount text field doesn't change to match. The cell in the content view does change though.2. Also, I've added a date picker, which works in the addView, but when I try to code it for the contentView, it doesn't work. I have a hunch that it's because I don't have the right data type in the ExpenseItem file.3. Lastly, I've tried to code the background color to change when the amount is within certain numbers, but I am not sure exactly where to put it. When I put in below the "func removeItems" I get an error that item is not in the scope.
addView
ExpenseItem
Expenses
|
|
William asks:
This is your code:
This looks (to me!) that you have a background in traditional, procedural programming. Perhaps C#, Java, Python, etc. IF something happens, I want THIS to happen. SwiftUI is a declarative language. Simply DECLARE how the view should look. Make it so! Here's how you declare the background color of a Text view.
How do you declare different colors for different circumstances? This uses the ternary operator to determine which color to use.
Maybe you want to try another method?
|
|
I put your code
and
right after
But I get the following error for either "Cannot declare local computed variable in result builder". Not sure if I am inserting it in the wrong place? or if there is something else I have to do before it will work |
|
William wonders:
You may need to start over with Day 1 and study the structure of Think of a In short, your If you decide that one of your structs is going to actually show something on a screen, fields, data, graphics, buttons, etc, then this The single requirement of the
The error message you received is clear.
This is saying you cannot declare a computed variable INSIDE a result builder. Take a look at my example. Which of those vars is a result builder? Spoiler alert: It's the Consequently you cannot do this:
So given what I said about |
|
So since it can't be in the body, |
SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.