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() } }
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