Post

Replies

Boosts

Views

Activity

Persisting SwiftData After App Deletion
Hello, I've encountered an issue where SwiftData remains in the /Users/(username)/Library/Containers/MyApp directory even after my MacOS app has been deleted. This behavior is not what I expected. Has anyone else faced this issue? Also, I'm wondering if there is a delay in the deletion process that might account for this. is there a known time lag before everything is cleared out? Thanks.
1
0
500
Mar ’24
SwiftData Migration Questions
I have couple of questions regarding app and schema version management related to SwiftData migration. For instance, it's common for the schema to change from V1 to V2 when updating an app from V1 to V2 and V3. This process seems reasonable to me. here's Moreover, if the versions go up to V10, does this mean I need to separate and organize stages for all migration codes, such as from V1 to V2, V2 to V3, up to V10, MigrationStages and Models for such exception handling? It was too wordy, here are my summary questions. 1. Can I limit to specific versions in my workspace?(e.g V1->2->3->1->2 .. so on) 2. if its not possible, For extensive versioning up to V10, should migration codes be organized for every incremental update for handling exceptions? 3. If I need to permanently record every stages and model, what improvements could be made to this structure?, can I get some useful tips?
0
0
413
Feb ’24
SwiftData Migration Error: Missing Attribute Values on Mandatory Relationship
I'm currently working on a data model migration in Swift using a custom schema migration plan. My project involves migrating settings from one schema version to another (SchemaV1 to SchemaV2). Both schema versions include a class named FSViz, but with slightly different properties. In the newer schema, SchemaV2, I introduced a new property named textSettings of type TextSetting, replacing the textColor property from SchemaV1. Here's a simplified version of my migration code and class definitions: Model: extension SchemaV1 { @Model public final class FSViz { @Attribute(.unique) public let id: UUID public var textColor: TextColor init(textColor: TextColor) { self.id = UUID() self.textColor = textColor } } } extension SchemaV2 { @Model public final class FSViz { @Attribute(.unique) public let id: UUID public var textSettings: TextSetting init(textSettings: TextSetting) { self.id = UUID() self.textSettings = textSettings } } } initMyApp: public struct InitMyApp { static func makeInitialFSViz() -> FSViz? { FSViz(textSettings: makeTextSettings()) } public static func makeFSViz() -> FSViz { FSViz(textSettings: makeTextSettings()) } static func makeTextSettings() -> TextSetting { TextSetting( textColor: TextColor(red: 1, green: 1, blue: 1, alpha: 1) ) } } MigrationPlan: enum MyAppMigrationPlan: SchemaMigrationPlan { static var schemas: [VersionedSchema.Type] { [SchemaV1.self, SchemaV2.self] } static var stages: [MigrationStage] { [migrateV1toV2] } static let migrateV1toV2 = MigrationStage.custom(fromVersion: SchemaV1.self, toVersion: SchemaV2.self, willMigrate: nil, didMigrate: { context in let fetchDescriptor = FetchDescriptor<SchemaV1.FSViz>() let allV1Vizs = try context.fetch(fetchDescriptor) for v1Viz in allV1Vizs { let newTextSetting = SchemaV2.TextSetting(textColor: v1Viz.textColor) let newViz = SchemaV2.FSViz(textSettings: newTextSetting) print("migration processing") context.insert(newViz) try context.save() } }) } MyAppContainer: public typealias FSViz = SchemaV2.FSViz public typealias TextSetting = SchemaV2.TextSetting @MainActor public let MyAppContainer: ModelContainer = { do { let schema = Schema([]) let configuration = ModelConfiguration() let container = try ModelContainer(for: FSViz.self, migrationPlan: MyAppMigrationPlan.self) let context = container.mainContext if try context.fetch(FetchDescriptor<FSViz>()).isEmpty { if let fsViz = InitWaveBar.makeInitialFSViz() { container.mainContext.insert(fsViz) } else { print("Error: makeInitialFSViz() returned nil") } } return container } catch { fatalError(error.localizedDescription) } }() However, when running the migration, I encounter the following error: Error Domain=NSCocoaErrorDomain Code=134110 "An error occurred during persistent store migration." UserInfo={entity=FSViz, attribute=textSettings, reason=Validation error missing attribute values on mandatory destination relationship} This error suggests that there are missing attribute values on the mandatory textSettings relationship in the destination schema. I've double-checked my migration logic to ensure that textSettings is correctly initialized and assigned, but the error persists. Questions: How can I resolve the "missing attribute values on mandatory destination relationship" error during the migration? Is there a specific aspect of handling relationships during migrations in Swift that I'm overlooking? Any insights or suggestions on how to troubleshoot and resolve this migration issue would be greatly appreciated.
1
1
1.4k
Feb ’24
How to Stop macOS Menu Bar Animation on a Secondary Screen
Hello everyone, I'm working on a macOS application and encountering an issue related to multi-screen setups. My application includes an animation in the menu bar, and it works perfectly on the primary screen. However, I want this animation to stop or not appear when the app is being used on a secondary monitor(non-focused monitor). (for cpu related problem, when it's 3 monitor -> x3 cpu with x3 animation objects) I've tried a few approaches to detect when the application is being used on a secondary screen and then stop the animation, but so far, I haven't had any success. The main challenge seems to be accurately determining the screen where the app is actively being used and controlling the animation accordingly. Has anyone faced a similar issue or have suggestions on how to effectively stop or prevent the menu bar animation from running on a secondary screen? Any guidance or insights would be greatly appreciated. Thank you in advance for your help!
1
0
704
Jan ’24
Cannot Install 'mirroringworkoutssample' App on Apple Watch due to Integrity Check Issue
I'm experiencing an issue trying to install the 'mirroringworkoutssample' app from the official Apple documentation on my Apple Watch. When attempting a direct installation from the Apple Watch, I receive an error stating, "Cannot install this app due to an inability to verify its integrity." Has anyone else encountered this problem or can provide any solutions or insights? ** I have a 'Development' type certificate that allows for watchOS(it includes iOS, tvOS ..) development. ** also added WKCompanionAppBundleIdentifier com.example.apple-samplecode.MirroringWorkoutsSample7C76V3X7AB.watchkitapp
0
0
740
Oct ’23
Issue with ScreenCaptureKit Performance(After Sonoma updates)
I'm encountering performance degradation with my application that utilizes ScreenCaptureKit. Even after explicitly disabling App Nap using the NSAppSleepDisabled key, the problem persists. My application, which relies heavily on ScreenCaptureKit for its core functionality, experiences significant performance drops after running for a short period. When I click on the application, the performance momentarily returns to normal but quickly deteriorates again. I've checked for memory leaks in my application and haven't found any issues in that regard. Has anyone experienced similar performance issues with ScreenCaptureKit? I'm keen to know if there are any known bugs or workarounds to mitigate this problem.
0
0
687
Oct ’23
Sudden Drop in CPU Utilization in macOS App After Extended Operation
I'm struggling with CPU performance and memory optimization for a macOS app I'm developing. I'm writing to ask for advice!!! The app I am developing consists of continuous real-time calculations and graphical elements. If I monitor the individual components, the CPU usage is as follows FetchAudioData (captures real-time data with Timer & performs calculations): 20%-30%. MEMU (graphics operation 1): 30% to 40%. FullScreen (graphics task 2): 20% to 40%. I run the app and see a CPU load of 50% to 100% consistently, based on 600% full capacity. However, after 3-4 hours of operation, the CPU utilization suddenly drops to around 10%. (It's hard to determine the exact cause because it's hard to monitor continuously during this time) Additionally, I aware of some memory issues and are dealing with them, but they don't appear to be fatal leaks, so I relegated them to lower priority tasks for now. At a crossroads, Should I prioritize code optimization, fix the small memory issue first, spend three to four hours of close monitoring, or perform a deeper understanding of the Mac system? The analysis process through Profile in Instruments is also tricky in terms of catching the exact moment of a sudden change in CPU utilization. I'm looking for advice from people who have some experience with performance/memory optimization in iOS environments, not necessarily macOS. I'm also wondering why the thread count in the picture goes into the 3000s after 3-4 hours. I'm also wondering if this is an issue with asynchronous processing. Any advice would be greatly appreciated in the comments. Thanks.
4
0
1.1k
Sep ’23