Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Bug? SwiftData + inheritance + optional many-to-one relationship
I've spent a few months writing an app that uses SwiftData with inheritance. Everything worked well until I tried adding CloudKit support. To do so, I had to make all relationships optional, which exposed what appears to be a bug. Note that this isn't a CloudKit issue -- it happens even when CloudKit is disabled -- but it's due to the requirement for optional relationships. In the code below, I get the following error on the second call to modelContext.save() when the button is clicked: Could not cast value of type 'SwiftData.PersistentIdentifier' (0x1ef510b68) to 'SimplePersistenceIdentifierTest.Computer' (0x1025884e0). I was surprised to find zero hit when Googling Could not cast value of type 'SwiftData.PersistentIdentifier'. Some things to note: Calling teacher.computers?.append(computer) instead of computer.teacher = teacher results in the same error. It only happens when Teacher inherits Person. It only happens if modelContext.save() is called both times. It
9
0
476
Jan ’26
Reply to Tahoe 26.2 breaks printing with PaperCut
So, looking at things from our side, I'm not sure. I found one bug on this (r.166518515) about accessing a custom directory (/Library//), but the analysis of the engineering team is that it isn't a bug in macOS 26.2... because it shouldn't work in macOS 26.0 EITHER. More specifically, it should only be accessing one of these documented directories: 2. Writing of files: pursuant to normal UNIX file permissions, filters and backends can read/write files to the cache directory specified by the CUPS_CACHEDIR environment variable, to the state directory specified by the CUPS_STATEDIR environment variable, to the temporary directory specified by the TMPDIR environment variable, and under the /private/var/db, /private/var/folders, /private/var/lib, /private/var/mysql, /private/var/run, /private/var/spool (except /private/var/spool/cups), /Library/Application Support, /Library/Caches, /Library/Logs, /Library/Preferences, /Library/WebServer, and /Users/Shared directories. FYI, that does suggest a possible workaround
Topic: App & System Services SubTopic: General Tags:
Jan ’26
SwiftData crash on adding sort argument to Query
Experiencing a crash that is only reproducible on TestFlight or AppStore version of the app, note this does not happen when running from Xcode. I've isolated the problem to sort argument being added to @Query that fetches a model that sorts based on inherited property. To reproduce: @Model class SuperModel { var createdAt: Date = .now } @available(macOS 26.0, *) @Model class SubModel: SuperModel { } @Query(sort: SubModel.createdAt, animation: .default) private var models: [SubModel]
1
0
151
Jan ’26
Reply to Sharing SwiftData between two apps
Assuming that your second app is under the same team, you can create an app group container for the two apps to share, and then have your first app move its data store to the container, your second app should then be able to access the store. To create an app group container, see Configuring app groups. To locate a SwiftData store to an app group container, see Share the same store file and the associate sample project. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jan ’26
Using Observations with SwiftData @Model
I want to use the Observations AsyncSequence on some SwiftData @Model instances to determine if internal calculations need to be done. When a simple property is linked to the Observations it fires CONTINUOUSLY even though no change is made to the model property. Also, when I try to observe a property which is a list of another @Model type the Observations sequence does not fire when I add or remove items. I am hoping to use the async-algorithm's merge function so all the associated sequences can be combined since if any of the associated events should fire the calculation event.
4
0
2.8k
Jan ’26
Reply to Extreme increase in app storage size after enabling CloudKit
When you use SwiftData + CloudKit, under the hood, the SwiftData framework converts SwiftData models to Core Data managed objects, and use NSPersistentCloudKitContainer to synchronize the objects with CloudKit. NSPersistentCloudKitContainer mirrors each Core Data managed object to (at least) a CloudKit record (CKRecord), as described in Reading CloudKit Records for Core Data. To manage the internal state of the synchronization, it adds a few tables to the store, and the ANSCKRECORDMETADATA table is one of them, which is used to store the metadata of the CloudKit records. The metadata includes the system fields and encoded data of every CloudKit record, so yes, you can see that the size of table gets quite large. The ANSCKRECORDMETADATA table is an internal data structure that NSPersistentCloudKitContainer creates and consumes. You can review the documentation mentioned above to make sure that your models are translated to CloudKit schema correctly, but other than that, I don't see a
Jan ’26
Performance in Large Datasets (SwiftUI+SwiftData app)
Hi everyone, In the simple app below, I have a QueryView that has LazyVStack containing 100k TextField's that edit the item's content. The items are fetched with a @Query. On launch, the app will generate 100k items. Once created, when I press any of the TextField's , a severe hang happens, and every time I type a single character, it will cause another hang over and over again. I looked at it in Instruments and it shows that the main thread is busy during the duration of the hang (2.31 seconds) updating QueryView. From the cause and effect graph, the update is caused by @Observable QueryController .(Bool). Why does it take too long to recalculate the view, given that it's in a LazyVStack? (In other words, why is the hang duration directly proportional to the number of items?) How to fix the performance of this app? I thought adding LazyVStack was all I need to handle the large dataset, but maybe I need to add a custom pagination with .fetchLimit on top of that? (I understand that ModelActor would be an alter
1
0
221
Jan ’26
macOS Tahoe generates low resolution wallpapers on certain Mac models
Dear Apple, please make sure this bug gets delivered to whoever is responsible. That's all I ask. Please don't let it sit for months unassigned. This is, by far, the worst bug I've ever found with the macOS wallpaper system. FB21532401 If you own a 13 2020 or newer MacBook pro model, set to the default resolution, and are running macOS Tahoe, macOS will significantly degrade the quality of any image set as wallpaper. When a still image is set as the wallpaper on macOS Tahoe, on some display configurations, the systems downscales the image to an incorrect size, resulting in pixelated wallpaper. The problem is exacerbated by the fact that macOS Wallpaper Agent appears to be using a less than ideal downscaling algorithm, which results in Super Mario Bros’ type pixelation (nearest neighbor) as opposed to any other reasonable modern method (like bicubic.) The issue does not repro on macOS Sequoia. Every model MacBook we’ve tested offers some resolutions with some form of this problem, but the 13” is the only one w
Topic: Design SubTopic: General
0
0
342
Jan ’26
Extreme increase in app storage size after enabling CloudKit
I have a SwiftData flashcard app which I am syncing with CloudKit using NSPersistentCloudKitContainer. While syncing itself is working perfectly, I have noticed a dramatic increase in the app size after enabling sync. Specifically, without CloudKit, 15k flashcards results in the default.store file being about 4.5 MB. With CloudKit, default.store is about 67 MB. I have inspected the store and found that most of this increase is due to the ANSCKRECORDMETADATA table. My question is, does implementing CloudKit normally cause this magnitude of increase in storage? If it doesn’t, is there something in my model, schema, implementation, etc. that could be causing it? Below are two other posts describing a similar issue, but neither with a solution. I replied to the first one about a month ago. I then submitted this to Developer Technical Support, but was asked to post my question in the forums, so here it is. Strange behavior with 100k+ records in NSPersistentCloudKitContainer Huge increase in sqlite file si
2
0
206
Jan ’26
Age Assurance Sandbox Testing - revoke vs declined
1)What's the relationship between Texas, child, 16-17, significant change declined from my 11:03 screenshot below and revoking? ie what situation could someone decline but not revoke or vice versa, what is the purpose of the distinction in testing or legally or implications/implementation 2) What is a cause besides a typo to receive the Can't trigger notification titled message after using Revoke? you can see by my screenshot by comparing the left and right half there is no title. 3) Even if i find a workaround perhaps my info will help someone else or be an opportunity for improved documentation see: see my 5:54pm second screenshot
0
0
134
Jan ’26
SwiftData CloudKit sync broken on iOS 26
Hi everyone, I’m running into a breaking issue with SwiftData automatic CloudKit syncing on iOS 26, and I'm trying to determine if this is a known regression or a new configuration requirement I missed. The Setup: My setup is extremely standard; I am using the default configuration exactly as described in Apple's documentation here: https://developer.apple.com/documentation/swiftdata/syncing-model-data-across-a-persons-devices The schema is very simple: A single @Model class. No relationships. The Issue: Prior to iOS 26, this exact app was successfully syncing data between devices and to iCloud without issues. Immediately after the iOS 26 update, syncing stopped completely. I haven't changed any code, but when I check the CloudKit Console, I am seeing some BAD_REQUEST errors during sync attempts. Since I am using the default SwiftData sync (and not manual CKRecord handling), I’m not sure how my client code could be triggering a bad request unless the schema requirements hav
1
0
295
Jan ’26
Providing pre-filled sample data for reviewer experience in Swift Student Challenge: Is it recommended?
Hi everyone, I am currently developing an app for my Swift Student Challenge submission. One of the key features of my app is visualizing user progress over time using SwiftData and Swift Charts. I have a concern regarding the first-time experience for the reviewer. Since the app relies on accumulated data to display meaningful trends, the dashboard/charts will appear empty on the very first launch, which might not fully showcase the visualization logic I’ve implemented. To ensure the reviewer can immediately grasp the app's potential within their limited review window, I am considering generating pre-populated sample data (mock data) only on the initial launch. Does Apple generally recommend including sample data in a challenge submission to better demonstrate UI/UX and data visualization capabilities? Or is it strictly preferred to present a fresh empty state, as a real first-time user would see it? I want to make sure I am following the best practices for the challenge while highlighting my techni
1
0
442
Jan ’26
Reply to unifiedContacts identifier vs contactRelations identifier
Here's the test code where I was attempting to find the relationship between records. // ContentView.swift // TestContactsProject // import SwiftUI import Contacts import OSLog extension Logger { private static var subsystem = Bundle.main.bundleIdentifier ?? com.myelin.TestContactsProject static let logic = Logger(subsystem: subsystem, category: logic) static let analitics = Logger(subsystem: subsystem, category: analitics) } struct ContentView: View { var body: some View { Text(Hello, World!) .padding() .onAppear { Task.init { await fetchAllContacts() //await fetchSpecificContacts() } } } func fetchSpecificContacts(keyStrings: [String]) { // Run this in the background async // Get access to the Contacts Store let store = CNContactStore() // Keys to fetch let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactIdentifierKey, CNContactRelationsKey] as [CNKeyDescriptor] // Search criteria let predicate = CNContact.predicateForContacts(withIdentifiers: keyStrings) d
Topic: App & System Services SubTopic: General Tags:
Dec ’25
Bug? SwiftData + inheritance + optional many-to-one relationship
I've spent a few months writing an app that uses SwiftData with inheritance. Everything worked well until I tried adding CloudKit support. To do so, I had to make all relationships optional, which exposed what appears to be a bug. Note that this isn't a CloudKit issue -- it happens even when CloudKit is disabled -- but it's due to the requirement for optional relationships. In the code below, I get the following error on the second call to modelContext.save() when the button is clicked: Could not cast value of type 'SwiftData.PersistentIdentifier' (0x1ef510b68) to 'SimplePersistenceIdentifierTest.Computer' (0x1025884e0). I was surprised to find zero hit when Googling Could not cast value of type 'SwiftData.PersistentIdentifier'. Some things to note: Calling teacher.computers?.append(computer) instead of computer.teacher = teacher results in the same error. It only happens when Teacher inherits Person. It only happens if modelContext.save() is called both times. It
Replies
9
Boosts
0
Views
476
Activity
Jan ’26
Reply to Tahoe 26.2 breaks printing with PaperCut
So, looking at things from our side, I'm not sure. I found one bug on this (r.166518515) about accessing a custom directory (/Library//), but the analysis of the engineering team is that it isn't a bug in macOS 26.2... because it shouldn't work in macOS 26.0 EITHER. More specifically, it should only be accessing one of these documented directories: 2. Writing of files: pursuant to normal UNIX file permissions, filters and backends can read/write files to the cache directory specified by the CUPS_CACHEDIR environment variable, to the state directory specified by the CUPS_STATEDIR environment variable, to the temporary directory specified by the TMPDIR environment variable, and under the /private/var/db, /private/var/folders, /private/var/lib, /private/var/mysql, /private/var/run, /private/var/spool (except /private/var/spool/cups), /Library/Application Support, /Library/Caches, /Library/Logs, /Library/Preferences, /Library/WebServer, and /Users/Shared directories. FYI, that does suggest a possible workaround
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’26
Reply to SwiftData crash on adding sort argument to Query
A similar issue was discussed in this thread. Your case has another layer of complexity - inheritance. Would you mind to have a check if your issue still happens without using inheritance? Also, would you mind to share the OS and SDK version you tested with? Thanks. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Jan ’26
SwiftData crash on adding sort argument to Query
Experiencing a crash that is only reproducible on TestFlight or AppStore version of the app, note this does not happen when running from Xcode. I've isolated the problem to sort argument being added to @Query that fetches a model that sorts based on inherited property. To reproduce: @Model class SuperModel { var createdAt: Date = .now } @available(macOS 26.0, *) @Model class SubModel: SuperModel { } @Query(sort: SubModel.createdAt, animation: .default) private var models: [SubModel]
Replies
1
Boosts
0
Views
151
Activity
Jan ’26
Reply to Sharing SwiftData between two apps
Assuming that your second app is under the same team, you can create an app group container for the two apps to share, and then have your first app move its data store to the container, your second app should then be able to access the store. To create an app group container, see Configuring app groups. To locate a SwiftData store to an app group container, see Share the same store file and the associate sample project. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Jan ’26
Using Observations with SwiftData @Model
I want to use the Observations AsyncSequence on some SwiftData @Model instances to determine if internal calculations need to be done. When a simple property is linked to the Observations it fires CONTINUOUSLY even though no change is made to the model property. Also, when I try to observe a property which is a list of another @Model type the Observations sequence does not fire when I add or remove items. I am hoping to use the async-algorithm's merge function so all the associated sequences can be combined since if any of the associated events should fire the calculation event.
Replies
4
Boosts
0
Views
2.8k
Activity
Jan ’26
Reply to Extreme increase in app storage size after enabling CloudKit
When you use SwiftData + CloudKit, under the hood, the SwiftData framework converts SwiftData models to Core Data managed objects, and use NSPersistentCloudKitContainer to synchronize the objects with CloudKit. NSPersistentCloudKitContainer mirrors each Core Data managed object to (at least) a CloudKit record (CKRecord), as described in Reading CloudKit Records for Core Data. To manage the internal state of the synchronization, it adds a few tables to the store, and the ANSCKRECORDMETADATA table is one of them, which is used to store the metadata of the CloudKit records. The metadata includes the system fields and encoded data of every CloudKit record, so yes, you can see that the size of table gets quite large. The ANSCKRECORDMETADATA table is an internal data structure that NSPersistentCloudKitContainer creates and consumes. You can review the documentation mentioned above to make sure that your models are translated to CloudKit schema correctly, but other than that, I don't see a
Replies
Boosts
Views
Activity
Jan ’26
Performance in Large Datasets (SwiftUI+SwiftData app)
Hi everyone, In the simple app below, I have a QueryView that has LazyVStack containing 100k TextField's that edit the item's content. The items are fetched with a @Query. On launch, the app will generate 100k items. Once created, when I press any of the TextField's , a severe hang happens, and every time I type a single character, it will cause another hang over and over again. I looked at it in Instruments and it shows that the main thread is busy during the duration of the hang (2.31 seconds) updating QueryView. From the cause and effect graph, the update is caused by @Observable QueryController .(Bool). Why does it take too long to recalculate the view, given that it's in a LazyVStack? (In other words, why is the hang duration directly proportional to the number of items?) How to fix the performance of this app? I thought adding LazyVStack was all I need to handle the large dataset, but maybe I need to add a custom pagination with .fetchLimit on top of that? (I understand that ModelActor would be an alter
Replies
1
Boosts
0
Views
221
Activity
Jan ’26
macOS Tahoe generates low resolution wallpapers on certain Mac models
Dear Apple, please make sure this bug gets delivered to whoever is responsible. That's all I ask. Please don't let it sit for months unassigned. This is, by far, the worst bug I've ever found with the macOS wallpaper system. FB21532401 If you own a 13 2020 or newer MacBook pro model, set to the default resolution, and are running macOS Tahoe, macOS will significantly degrade the quality of any image set as wallpaper. When a still image is set as the wallpaper on macOS Tahoe, on some display configurations, the systems downscales the image to an incorrect size, resulting in pixelated wallpaper. The problem is exacerbated by the fact that macOS Wallpaper Agent appears to be using a less than ideal downscaling algorithm, which results in Super Mario Bros’ type pixelation (nearest neighbor) as opposed to any other reasonable modern method (like bicubic.) The issue does not repro on macOS Sequoia. Every model MacBook we’ve tested offers some resolutions with some form of this problem, but the 13” is the only one w
Topic: Design SubTopic: General
Replies
0
Boosts
0
Views
342
Activity
Jan ’26
Extreme increase in app storage size after enabling CloudKit
I have a SwiftData flashcard app which I am syncing with CloudKit using NSPersistentCloudKitContainer. While syncing itself is working perfectly, I have noticed a dramatic increase in the app size after enabling sync. Specifically, without CloudKit, 15k flashcards results in the default.store file being about 4.5 MB. With CloudKit, default.store is about 67 MB. I have inspected the store and found that most of this increase is due to the ANSCKRECORDMETADATA table. My question is, does implementing CloudKit normally cause this magnitude of increase in storage? If it doesn’t, is there something in my model, schema, implementation, etc. that could be causing it? Below are two other posts describing a similar issue, but neither with a solution. I replied to the first one about a month ago. I then submitted this to Developer Technical Support, but was asked to post my question in the forums, so here it is. Strange behavior with 100k+ records in NSPersistentCloudKitContainer Huge increase in sqlite file si
Replies
2
Boosts
0
Views
206
Activity
Jan ’26
Age Assurance Sandbox Testing - revoke vs declined
1)What's the relationship between Texas, child, 16-17, significant change declined from my 11:03 screenshot below and revoking? ie what situation could someone decline but not revoke or vice versa, what is the purpose of the distinction in testing or legally or implications/implementation 2) What is a cause besides a typo to receive the Can't trigger notification titled message after using Revoke? you can see by my screenshot by comparing the left and right half there is no title. 3) Even if i find a workaround perhaps my info will help someone else or be an opportunity for improved documentation see: see my 5:54pm second screenshot
Replies
0
Boosts
0
Views
134
Activity
Jan ’26
SwiftData CloudKit sync broken on iOS 26
Hi everyone, I’m running into a breaking issue with SwiftData automatic CloudKit syncing on iOS 26, and I'm trying to determine if this is a known regression or a new configuration requirement I missed. The Setup: My setup is extremely standard; I am using the default configuration exactly as described in Apple's documentation here: https://developer.apple.com/documentation/swiftdata/syncing-model-data-across-a-persons-devices The schema is very simple: A single @Model class. No relationships. The Issue: Prior to iOS 26, this exact app was successfully syncing data between devices and to iCloud without issues. Immediately after the iOS 26 update, syncing stopped completely. I haven't changed any code, but when I check the CloudKit Console, I am seeing some BAD_REQUEST errors during sync attempts. Since I am using the default SwiftData sync (and not manual CKRecord handling), I’m not sure how my client code could be triggering a bad request unless the schema requirements hav
Replies
1
Boosts
0
Views
295
Activity
Jan ’26
Reply to SwiftData with CloudKit Sync Issue
I have had the same issue with SwiftData and CloudKit after iOS 26 release. My setup is super minimal and using the default configuration so no clue what could have gone wrong on my side.
Replies
Boosts
Views
Activity
Jan ’26
Providing pre-filled sample data for reviewer experience in Swift Student Challenge: Is it recommended?
Hi everyone, I am currently developing an app for my Swift Student Challenge submission. One of the key features of my app is visualizing user progress over time using SwiftData and Swift Charts. I have a concern regarding the first-time experience for the reviewer. Since the app relies on accumulated data to display meaningful trends, the dashboard/charts will appear empty on the very first launch, which might not fully showcase the visualization logic I’ve implemented. To ensure the reviewer can immediately grasp the app's potential within their limited review window, I am considering generating pre-populated sample data (mock data) only on the initial launch. Does Apple generally recommend including sample data in a challenge submission to better demonstrate UI/UX and data visualization capabilities? Or is it strictly preferred to present a fresh empty state, as a real first-time user would see it? I want to make sure I am following the best practices for the challenge while highlighting my techni
Replies
1
Boosts
0
Views
442
Activity
Jan ’26
Reply to unifiedContacts identifier vs contactRelations identifier
Here's the test code where I was attempting to find the relationship between records. // ContentView.swift // TestContactsProject // import SwiftUI import Contacts import OSLog extension Logger { private static var subsystem = Bundle.main.bundleIdentifier ?? com.myelin.TestContactsProject static let logic = Logger(subsystem: subsystem, category: logic) static let analitics = Logger(subsystem: subsystem, category: analitics) } struct ContentView: View { var body: some View { Text(Hello, World!) .padding() .onAppear { Task.init { await fetchAllContacts() //await fetchSpecificContacts() } } } func fetchSpecificContacts(keyStrings: [String]) { // Run this in the background async // Get access to the Contacts Store let store = CNContactStore() // Keys to fetch let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactIdentifierKey, CNContactRelationsKey] as [CNKeyDescriptor] // Search criteria let predicate = CNContact.predicateForContacts(withIdentifiers: keyStrings) d
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’25