Post

Replies

Boosts

Views

Activity

Reply to iOS 17 - TextField color does not changes with state is updated
Change the code to confirm that the issue affects TextField, but not Text. The code below change the Text color to red when 1 is entered, but not change the TextField color. struct ContentView: View { @State private var numberText = "" var color: Color { let result = (Int(numberText) ?? 0) <= 0 if result { return .black } return .red } var body: some View { VStack { TextField("Enter a number", text: $numberText) .font(.title) .foregroundStyle( color ) Text("Font color will turn red if number > 0") .foregroundStyle( color ) } .padding() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to iOS 17 - TextField color does not changes with state is updated
@Claude31 the print output as I expected, the the TextField color does not update on iOS 17 simulator. Here is the output for input 0, 1, A: numberText Int nil result = true numberText 0 Int Optional(0) result = true numberText Int nil result = true numberText 1 Int Optional(1) result = false numberText Int nil result = true numberText A Int nil result = true
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to @Attribute 'unique' and complex keys
I tested define @Attribute(.unique) multiple times and seems not a correct solution: @Model final class Book { @Attribute(.unique) var title: String @Attribute(.unique) var author: String } I tried to insert books have some wried result: container.mainContext.insert(BooK(title: "book 1", author: "author 1")) try? container.mainContext.save() // 1 book inserted container.mainContext.insert(BooK(title: "book 1", author: "author 1")) try? container.mainContext.save() // 1 book inserted as expected container.mainContext.insert(BooK(title: "book 2", author: "author 1")) try? container.mainContext.save() // "book 2" replace "book 1", and 1 book is left.
Jun ’23