Similar to the podcast app, I need to keep track of how far the audio has been played. My solution right now is to start a timer that updates a swiftdata object property. This will later be an TimeInterval, but right now I am working with the SwiftData Template. Since a playback can be started from many places in the app, I need to write a function that can be accessed anywhere. None of the places I tried (extensions, global, within class) support @Query so I need to use another way.
Post
Replies
Boosts
Views
Activity
Try to catch the error and see what that tells you. It is usually more than the crash message.
[quote='756467021, chijun89, /thread/756467, /profile/chijun89']
do {
let modelContainer = try ModelContainer(for: Attachment.self, configurations: self.modelConfiguration)
} catch {
print("\(error) \(error.localizedDescription)")
}
[/quote]
These structs are not supposed to read any data. They should be created inside your ModelActor and since they are sendable you can transfer them to a Main Actor context to display them. AFAIK using Query should also be fine tho it doesn't fit my needs in my project. I have never worked with UIKit, therefore I can't help you with that.
Thank you so much for that response, Quinn. My understanding of @MainActor was just wrong. The functions I was referring to work just fine when marked @MainActor. Now I marked all of my View-Structs with @MainActor and my migration is complete. I was still using Xcode 15.4. Thank you so much for your help.
@SpaceMan I am not exactly sure what you mean. Do you need to sort your fetched identifiers? Your fetchDescriptor has a sortBy property that you can assign SortDescriptors to.
var descriptor = FetchDescriptor(predicate: #Predicate { item in
item.timestamp.timeIntervalSinceNow >= 0
})
descriptor.sortBy = [SortDescriptor(\Item.timestamp)]
How I observed the memory issues:
Installed app on device (Memory at around 25MB)
Added 10 models (after that Memory at around 29MB)
Started Timer and waited. (3min -> 70MB, 47min -> 1,05GB, 49min -> 1,07GB -> Hang detection showed hangs at around 150ms each)
Stopped timer and waited for 10 minutes (Memory usage dropped to 1,06GB, went up to 1,08GB and after 10 minutes it was back at 1,06GB) [1/2]
After 64 min the memory was down to 1,03GB so it seems like the system recycles the memory slowly.
Phone has not been touched in the entire time and it has always been in the foreground. Even if the memory is slowly recycled that happens too late since such a simple app should not be consuming so much memory. Clearly something is not working as expected here.
Thanks for the reference to the other post but that is not relevant for my app. [2/2]
The first message (Attempted to reg...) is a fault, library is "Accounts", subsystem is "com.apple.accounts" and category is "core".
The second message is an error, library is iTunsCloud, subsystem is "com.apple.amp.iTunesCloud" and category is "Default". I can right click this one and choose "Hide similar items" which works but is not available for the first message.
I am currently running iOS 17.6.1 (21G93) and Xcode Version 15.4 (15F31d)
Maybe you can elaborate what App Review gave for an explanation. Referring to Guideline 4.3.0 can be anything. Once again this is more of a rant that anything else we can help you with.