unfortunately, nope. the work around is to do something like
class SearchHistory {
private static let maxHistoryItems = 50
@AppStorage("searchHistory") private var historyData: Data = Data()
var recentSearches: [SearchHistoryItem] {
get {
guard let items = try? JSONDecoder().decode([SearchHistoryItem].self, from: historyData)
else { return [] }
return items
}
set {
let limitedItems = Array(newValue.prefix(Self.maxHistoryItems))
if let data = try? JSONEncoder().encode(limitedItems) {
historyData = data
}
}
}
}
Post
Replies
Boosts
Views
Activity
Sorry for my delay, thank you, it makes sense. I wish Apple documentation was more clear and gave more explanations on not only the intended way to use an API like Swift Data but also why it is a certain way and also compared with incorrect usage.
I also have this issue, no change in Xcode 16 RC and iOS 18 RC. this is very disappointing and will break a lot of apps. What's up apple? Or am I missing something how to fix this?
I have a horizontal scroll view and each view has a drag gesture which on vertical drag would dismiss the view. This worked in iOS 17.5 and Xcode 15.4 but not on the latest as I mention above.
My fix is to use .simultaneousGesture rather than just .gesture modifier block, it seems to work and the view is more dynamic as the horizontal scroll and individual view's drag gestures work together simultaneously rather than one or the other. Is this the intended behavior Apple wants? That's fine, but more explanation and documentation would really go a long way to help here.
I would think you would want the duplicate behavior in this example? I can often have two people with the same first and last name but they are two different people, and the different age could be that distinguishing factor. I'm trying to think, when would you want this merged and not duplicated? Duplicating here seems to be the safe / correct behavior, no?
I think it's not about preference or ego, but how it affects the discoverability algorithm. Apple should follow SO or reddit as the OP suggests; probably SO approach, IMO, but either is better.
Also unrelated but if I have your attention, I am noticing for some threads I am unable to boost or upvote any post, is this a bug or intended behavior?
This is a good question that I wish apple would discuss more. Yes as people suggest, it is a wrapper for NSManagedObjectID and it will change until its first save, as discussed here https://www.hackingwithswift.com/quick-start/swiftdata/how-to-save-a-swiftdata-object
It's still not clear to me what is best practice, particularly when syncing with a cloud service or database such as postgres. Should I override the swift data id var with my postgres uuid? or have a separate var "cloudID" for it? Has anyone built real apps (not toy demos) with swift data and a server and found any gotchas or advice?
how are you doing now? Has Beta 3 resolved this?
Good solution and good question. How did it work out in your code? I'm also wondering, has Apple fixed this for latest SwiftUI (WWDC 24, iOS 18 etc.) ?
I also have this issue. Now our project had Xcode cloud setup with a different repo in the past, I have added our new repo (its a complete rewrite) so there are 2 primary repos in Xcode cloud, and I created a workflow targeting the new repo. Everything seems to work except neither Xcode or AppStore Connect can see any branches, and so I can't trigger a build.
Is deleting all Xcode Cloud data and starting over the only solution?
agreed this is such a weird miss by apple
I have the same issue, it seems like something apple should fix to be honest. Did you find any updates?
did you find any updates? In my case it doesn't crash but it inserts the duplicate anyway, it doesn't properly upsert the existing one.
I have this same question, surprised the apple one doesn't let us edit the check color