Tested with iOS 18.1 and Xcode 16.1 beta and the issue still exists
Post
Replies
Boosts
Views
Activity
still reproducible after updated to Xcode 16 beta 4
tested with iOS 17.1 beta and the issue still exists
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()
}
}
@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
My workaround: create our own unique key with title and author:
@Model final class Book {
@Attribute(.unique)
var titleAndAuthor: String
var title: String
var author: String
init(title: String, author: String) {
self.title = title
self.author = author
titleAndAuthor = self.title + self.author
}
}
I have a similar question also, for now I would create and UUID instead of complex key, e.g.:
@Attribute(.unique) var identifier: UUID
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.
I got a random failure for Phrase SDK
failed downloading 'https://github.com/phrase/ios-sdk/releases/download/4.0.1/PhraseSDK.xcframework.zip' which is required by binary target 'PhraseSDK': downloadError("Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made