Post

Replies

Boosts

Views

Activity

Reply to How to limit my numbers in Swift
I want the limit of health points of my characters to be exactly between 0 and 100.  What in your code represents health points? If my character loses health points, Where is the code that your character loses health points? if he gains health points, Where is the code that your character gains health points? Better if you continued your old thread with adding this code.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Protocol Not Working
I have an identifier I named r in the storyboard. That has no meaning. Even if you have a segue with identifier r, you need to properly invoke it. By the way, print("segue identifier", segue.identifier) needs to places outside of if-statement to explore what's happening to your project.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Using Bindings with (Arrays of) Enumerations
If you would not mind defining a read-write computed property, you can write something like this: extension Row { &#9;&#9;var textBody: String { &#9;&#9;&#9;&#9;get { &#9;&#9;&#9;&#9;&#9;&#9;switch self { &#9;&#9;&#9;&#9;&#9;&#9;case .text(let body): &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return body &#9;&#9;&#9;&#9;&#9;&#9;default: &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return "" &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;mutating set { &#9;&#9;&#9;&#9;&#9;&#9;self = .text(newValue) &#9;&#9;&#9;&#9;} &#9;&#9;} } struct StuffView: View { &#9;&#9;@State var stuff: [Row] = [.text("foo"), .text("bar")] &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;List { &#9;&#9;&#9;&#9;&#9;&#9;ForEach(stuff.indices) { idx in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;switch stuff[idx] { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;case .text(let body): &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;TextField( &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;"Row \(idx)", &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;text: $stuff[idx].textBody //<- &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Spacer() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(body) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21