Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

SwiftUI Sheet view with @Query loses model context
I've run into a strange issue. If a sheet loads a view that has a SwiftData @Query, and there is an if statement in the view body, I get the following error when running an iOS targetted SwiftUI app under MacOS 26.1: Set a .modelContext in view's environment to use Query While the view actually ends up loading the correct data, before it does, it ends up re-creating the sqlite store (opening as /dev/null). The strange thing is that this only happens if there is an if statement in the body. The statement need not ever evaluate true, but it causes the issue. Here's an example. It's based on the default xcode new iOS project w/ SwiftData: struct ContentView: View { @State private var isShowingSheet = false var body: some View { Button(action: { isShowingSheet.toggle() }) { Text(Show Sheet) } .sheet(isPresented: $isShowingSheet, onDismiss: didDismiss) { VStack { ContentSheetView() } } } func didDismiss() { } } struct ContentSheetView: View { @Environment(.modelContext) private var modelContext @
2
0
224
Nov ’25
Reply to SwiftData Versioning with Top-Level Models
If you are making a lightweight migration-able change on a model and the model isn't in a versioned schema (VersionedSchema), that is fine. If you are defining a migration plan, you will need versioned schemas to create migration stages, won't you? Moving models to a schema should be fine, as discussed here. The post was written last year. SwiftData has evolved. If you see anything wrong when trying the method, I'd be interested in taking a closer look. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Nov ’25
SwiftData Versioning with Top-Level Models
If an app is using top-level models, meaning they exist outside the VersionedSchema enum, is it safe to keep them outside of the VersionedSchema enum and use a migration plan for simple migrations. Moving the models within the VersionedSchema enum I believe would change the identity of the models and result in data being lost, although correct me if I'm wrong in that statement. The need presently is just to add another variable to the model and then set that variable within the init function: var updateId = UUID() The app is presently in TestFlight although I'd like to preserve data for users that are currently using the app. The data within SwiftData is synchronized with CloudKit and so I'd also like to avoid any impact to synchronization. Any thoughts on this would be greatly appreciated.
1
0
184
Nov ’25
INQUIRY command is ILLEGAL REQUEST
I am developing a DriverKit driver with the goal of sending vendor-specific commands to a USB storage device. I have successfully created the DriverKit driver, and when I connect the USB storage device, it appears correctly in IORegistryExplorer. My driver class inherits from IOUserSCSIPeripheralDeviceType00 in the SCSIPeripheralsDriverKit framework. I also created a UserClient class that inherits from IOUserClient, and from its ExternalMethod I tried sending an INQUIRY command as a basic test to confirm that command transmission works. However, the device returns an ILLEGAL REQUEST (Sense Key 0x5 / ASC 0x20). Could someone advise what I might be doing wrong? Below are the logs output from the driver: 2025-11-14 21:00:43.573730+0900 0x26e9 Default 0x0 0 0 kernel: (SampleDriverKitApp.SampleDriverKitDriver.dext) [DEBUG] Driver - NewUserClient() - Finished. 2025-11-14 21:00:43.573733+0900 0x26e9 Default 0x0 0 0 kernel: (SampleDriverKitApp.SampleDriverKitDriver.dext) [DEBUG] UserClient - Start()
1
0
329
Nov ’25
NSButton + TtGC6AppKit18_NSCoreHostingViewVS_12AppKitButton - Image Alignment Changed/Broken in Minor macOS 26.1 Update
I just updated to macOS 26.1. I have a pure AppKit app (I guess that's not possible anymore but as close to a pure AppKit app as you can get). I use NSButton with the glass bezel style and SF symbol images. It looks like the minor OS update brought layout changes because now some of these buttons are scaling the symbol image much larger than was being done on macOS 26. The image can sometimes draw outside the glass 'bezel'. It looks like using the 'info' symbol in a button results in much larger image scaling than it did on the previous Tahoe for some SF Symbols. With the glass bezel style and a SF Symbol image how am I supposed to consistently make the button look good? With certain symbols I have to use imageScaling NSImageScaleProportionallyUpOrDown and on others I have to use NSImageScaleProportionallyDown. If I'm using a system image shouldn't it just do the right thing? Is trial and error the only way to tell? That's what I was doing before but it seems that the minor 26.1 update changed things. Additio
1
0
105
Nov ’25
Reply to Why can’t sandboxed mac app store apps have full disk access available in the system settings for full disk access?
You’re conflating a bunch of different things here. [quote='807142021, andyt, /thread/807142, /profile/andyt'] I discovered mac app store apps in release mode cannot access … other command line programs [/quote] First up, terminology. When we talk about Debug and Release mode, those are build configurations. That’s technically independent from Development and Distribution code signing. While it’s common for folks to combine the Debug build configuration with Development signing, that’s not required. In fact, sometimes it’s useful to mix these up. I explain one such case in Isolating Code Signing Problems from Build Problems. None of that’s related your actual issue though. Rather, App Store apps must enable the App Sandbox, and that limits the app’s ability to access the file system. And specifically, when it comes to executables: If a sandboxed app spawns a child process, that process inherits the app’s static sandbox. Many command-line tools don’t work when sandboxed. A sandboxed app can only run e
Topic: Privacy & Security SubTopic: General Tags:
Nov ’25
Reply to Strange behavior with 100k+ records in NSPersistentCloudKitContainer
I’m having a similar problem. I found a reddit post about this issue where the author writes, “I’m guessing it only shows up for devs who bulk import/delete during testing, while normal users with a few hundred records never notice.” Which makes sense because I am also bulk importing. I’m seeing about a 6-8 times increase between the local storage and CloudKit. (Specifically, 15k records comes out to around 13mb of local storage, but 100mb with CloudKit enabled. ANSCKRECORDMETADATA appears to be the main culprit.) I’m making a flashcard app, and of course users can import as many cards as they want, which could become a storage problem pretty quickly. From my understanding, and as you mentioned, a storage increase is expected. But the increase I’m seeing just seems excessive. … Or is it? I can’t really find anything on what to expect. I wonder if there’s something I can change in the model to make this work. Or maybe the problem is unique to NSPersistentCloudKitContainer and I should look at other sync option
Nov ’25
PhotosPickerItem.itemIdentifier always nil
I'm using the SwiftUI Photos Picker to select videos from the users Photos library and then opening the video using the PhotosPickerItem. I'm looking for a way to allow the user to open the same video on their other devices as the app uses SwiftData and CloudKit to provide access to a recently watched list of videos. The URL from the PhotosPickerItem appears to be device specific and so I was looking to see if I can use the itemIdentifier and then the init that takes the itemIdentifier to create the PhotosPickerItem on the other devices. The itemIdentifier however is always nil and so wouldn't be able to be used in this way. Is there an alternative approach whereby the users can open a video using a PhotosPickerItem and that item would be viewable on their other devices with an item identifier or a URL that is device agnostic. This approach should also not involve copying the video into other storage as it would simply expand the use of the users iCloud storage, providing a less than ideal user exper
1
0
689
Nov ’25
Reply to Provider entitlements check failed
Before I file a bug report, does the Info.plist need an entry that matches the entitlement? Sort of. The exact behavior here is going to depend on exactly what you're matching, but the typical configuration is that your Info.plist and entitlement configuration would both define IOPCIPrimaryMatch but they wouldn't necessarily be identical. In the case of the dev only entitlement they'd basically never be identical, since the dev entitlement matches everything. For reference, the configuration of the DEXT I tested the entitlement with is: Info.plist: ... IOPCIPrimaryMatch = 0x400014e4&0xf000ffff ... However, going over the details again, I do have one minor correction. Above I said that the Entitlement.plist value should be 0xFFFFFFFF&0x00000000, however, that's wrong. That's the value that's embedded in the provisioning profile, which escapes the &. The Entitlement.plist uses the & directly, so the correct value is actually: Entitlement.plist: ... com.apple.developer.driverkit.transport.pci I
Topic: App & System Services SubTopic: Drivers Tags:
Nov ’25
The relationship between age verification and permission kit isn't clear (IMO)
I'm trying to digest and understand the new set of APIs relating age verification that were released last week. I have say that without some cohesive overview, example app, just a simple diagram showing the relationship of everything, its not at all clear to me what's going on nor what an app developer is expected to do to use these apis (I'm a senior engineer with 15 year's iOS experience, but hey maybe I'm just a bit slow in the head). I have a few questions, but the topic of this post is what is the relationship between age verification i.e. between the declared age range/significant change and Permission Kit? The documentation for the former mentions the Significant Change API/Topic (https://developer.apple.com/news/?id=2ezb6jhj / https://developer.apple.com/documentation/PermissionKit/SignificantAppUpdateTopic). Now the Significant Change Topic is documented as being part of PermissionKit, however the documentation for that (https://developer.apple.com/documentation/permissionkit) State
1
0
216
Nov ’25
Reply to How to correctly fetch data using SwiftData
My code for the last block: import SwiftUI import SwiftData struct HomeView: View { @Query var profiledata: [allProfileData] //get all profiledata @Environment(.modelContext) private var modelContext @State private var profileImage: Image = Image(DefaultProfile) var body: some View { VStack { profileImage } .onAppear() { let fetchRequest = FetchDescriptor() let fetchedData = try? modelContext.fetch(fetchRequest) print(Fetched count: (fetchedData?.count ?? 0)) if let imageData = profiledata.first?.profileImageData, let uiImage = UIImage(data: imageData) { profileImage = Image(uiImage: uiImage) } else { profileImage = Image(DefaultProfile) } //yes, I realize that I could use profiledata.first?.profileImage but I was just checking if profileImageData would save or not } } }
Topic: UI Frameworks SubTopic: General Tags:
Nov ’25
How to correctly fetch data using SwiftData
Hi there! I'm making an app that stores data for the user's profile in SwiftData. I was originally going to use UserDefaults but I thought SwiftData could save Images natively but this is not true so I really could switch back to UserDefaults and save images as Data but I'd like to try to get this to work first. So essentially I have textfields and I save the values of them through a class allProfileData. Here's the code for that: import SwiftData import SwiftUI @Model class allProfileData { var profileImageData: Data? var email: String var bio: String var username: String var profileImage: Image { if let data = profileImageData, let uiImage = UIImage(data: data) { return Image(uiImage: uiImage) } else { return Image(DefaultProfile) } } init(email:String, profileImageData: Data?, bio: String, username:String) { self.profileImageData = profileImageData self.email = email self.bio = bio self.username = username } } To save this I create a new class (I think, I'm new) and save it throu
7
0
338
Nov ’25
SwiftUI Sheet view with @Query loses model context
I've run into a strange issue. If a sheet loads a view that has a SwiftData @Query, and there is an if statement in the view body, I get the following error when running an iOS targetted SwiftUI app under MacOS 26.1: Set a .modelContext in view's environment to use Query While the view actually ends up loading the correct data, before it does, it ends up re-creating the sqlite store (opening as /dev/null). The strange thing is that this only happens if there is an if statement in the body. The statement need not ever evaluate true, but it causes the issue. Here's an example. It's based on the default xcode new iOS project w/ SwiftData: struct ContentView: View { @State private var isShowingSheet = false var body: some View { Button(action: { isShowingSheet.toggle() }) { Text(Show Sheet) } .sheet(isPresented: $isShowingSheet, onDismiss: didDismiss) { VStack { ContentSheetView() } } } func didDismiss() { } } struct ContentSheetView: View { @Environment(.modelContext) private var modelContext @
Replies
2
Boosts
0
Views
224
Activity
Nov ’25
Reply to SwiftData Versioning with Top-Level Models
If you are making a lightweight migration-able change on a model and the model isn't in a versioned schema (VersionedSchema), that is fine. If you are defining a migration plan, you will need versioned schemas to create migration stages, won't you? Moving models to a schema should be fine, as discussed here. The post was written last year. SwiftData has evolved. If you see anything wrong when trying the method, I'd be interested in taking a closer look. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Nov ’25
SwiftData Versioning with Top-Level Models
If an app is using top-level models, meaning they exist outside the VersionedSchema enum, is it safe to keep them outside of the VersionedSchema enum and use a migration plan for simple migrations. Moving the models within the VersionedSchema enum I believe would change the identity of the models and result in data being lost, although correct me if I'm wrong in that statement. The need presently is just to add another variable to the model and then set that variable within the init function: var updateId = UUID() The app is presently in TestFlight although I'd like to preserve data for users that are currently using the app. The data within SwiftData is synchronized with CloudKit and so I'd also like to avoid any impact to synchronization. Any thoughts on this would be greatly appreciated.
Replies
1
Boosts
0
Views
184
Activity
Nov ’25
INQUIRY command is ILLEGAL REQUEST
I am developing a DriverKit driver with the goal of sending vendor-specific commands to a USB storage device. I have successfully created the DriverKit driver, and when I connect the USB storage device, it appears correctly in IORegistryExplorer. My driver class inherits from IOUserSCSIPeripheralDeviceType00 in the SCSIPeripheralsDriverKit framework. I also created a UserClient class that inherits from IOUserClient, and from its ExternalMethod I tried sending an INQUIRY command as a basic test to confirm that command transmission works. However, the device returns an ILLEGAL REQUEST (Sense Key 0x5 / ASC 0x20). Could someone advise what I might be doing wrong? Below are the logs output from the driver: 2025-11-14 21:00:43.573730+0900 0x26e9 Default 0x0 0 0 kernel: (SampleDriverKitApp.SampleDriverKitDriver.dext) [DEBUG] Driver - NewUserClient() - Finished. 2025-11-14 21:00:43.573733+0900 0x26e9 Default 0x0 0 0 kernel: (SampleDriverKitApp.SampleDriverKitDriver.dext) [DEBUG] UserClient - Start()
Replies
1
Boosts
0
Views
329
Activity
Nov ’25
NSButton + TtGC6AppKit18_NSCoreHostingViewVS_12AppKitButton - Image Alignment Changed/Broken in Minor macOS 26.1 Update
I just updated to macOS 26.1. I have a pure AppKit app (I guess that's not possible anymore but as close to a pure AppKit app as you can get). I use NSButton with the glass bezel style and SF symbol images. It looks like the minor OS update brought layout changes because now some of these buttons are scaling the symbol image much larger than was being done on macOS 26. The image can sometimes draw outside the glass 'bezel'. It looks like using the 'info' symbol in a button results in much larger image scaling than it did on the previous Tahoe for some SF Symbols. With the glass bezel style and a SF Symbol image how am I supposed to consistently make the button look good? With certain symbols I have to use imageScaling NSImageScaleProportionallyUpOrDown and on others I have to use NSImageScaleProportionallyDown. If I'm using a system image shouldn't it just do the right thing? Is trial and error the only way to tell? That's what I was doing before but it seems that the minor 26.1 update changed things. Additio
Replies
1
Boosts
0
Views
105
Activity
Nov ’25
Reply to Why can’t sandboxed mac app store apps have full disk access available in the system settings for full disk access?
You’re conflating a bunch of different things here. [quote='807142021, andyt, /thread/807142, /profile/andyt'] I discovered mac app store apps in release mode cannot access … other command line programs [/quote] First up, terminology. When we talk about Debug and Release mode, those are build configurations. That’s technically independent from Development and Distribution code signing. While it’s common for folks to combine the Debug build configuration with Development signing, that’s not required. In fact, sometimes it’s useful to mix these up. I explain one such case in Isolating Code Signing Problems from Build Problems. None of that’s related your actual issue though. Rather, App Store apps must enable the App Sandbox, and that limits the app’s ability to access the file system. And specifically, when it comes to executables: If a sandboxed app spawns a child process, that process inherits the app’s static sandbox. Many command-line tools don’t work when sandboxed. A sandboxed app can only run e
Topic: Privacy & Security SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’25
Reply to Strange behavior with 100k+ records in NSPersistentCloudKitContainer
I’m having a similar problem. I found a reddit post about this issue where the author writes, “I’m guessing it only shows up for devs who bulk import/delete during testing, while normal users with a few hundred records never notice.” Which makes sense because I am also bulk importing. I’m seeing about a 6-8 times increase between the local storage and CloudKit. (Specifically, 15k records comes out to around 13mb of local storage, but 100mb with CloudKit enabled. ANSCKRECORDMETADATA appears to be the main culprit.) I’m making a flashcard app, and of course users can import as many cards as they want, which could become a storage problem pretty quickly. From my understanding, and as you mentioned, a storage increase is expected. But the increase I’m seeing just seems excessive. … Or is it? I can’t really find anything on what to expect. I wonder if there’s something I can change in the model to make this work. Or maybe the problem is unique to NSPersistentCloudKitContainer and I should look at other sync option
Replies
Boosts
Views
Activity
Nov ’25
PhotosPickerItem.itemIdentifier always nil
I'm using the SwiftUI Photos Picker to select videos from the users Photos library and then opening the video using the PhotosPickerItem. I'm looking for a way to allow the user to open the same video on their other devices as the app uses SwiftData and CloudKit to provide access to a recently watched list of videos. The URL from the PhotosPickerItem appears to be device specific and so I was looking to see if I can use the itemIdentifier and then the init that takes the itemIdentifier to create the PhotosPickerItem on the other devices. The itemIdentifier however is always nil and so wouldn't be able to be used in this way. Is there an alternative approach whereby the users can open a video using a PhotosPickerItem and that item would be viewable on their other devices with an item identifier or a URL that is device agnostic. This approach should also not involve copying the video into other storage as it would simply expand the use of the users iCloud storage, providing a less than ideal user exper
Replies
1
Boosts
0
Views
689
Activity
Nov ’25
Reply to Provider entitlements check failed
Before I file a bug report, does the Info.plist need an entry that matches the entitlement? Sort of. The exact behavior here is going to depend on exactly what you're matching, but the typical configuration is that your Info.plist and entitlement configuration would both define IOPCIPrimaryMatch but they wouldn't necessarily be identical. In the case of the dev only entitlement they'd basically never be identical, since the dev entitlement matches everything. For reference, the configuration of the DEXT I tested the entitlement with is: Info.plist: ... IOPCIPrimaryMatch = 0x400014e4&0xf000ffff ... However, going over the details again, I do have one minor correction. Above I said that the Entitlement.plist value should be 0xFFFFFFFF&0x00000000, however, that's wrong. That's the value that's embedded in the provisioning profile, which escapes the &. The Entitlement.plist uses the & directly, so the correct value is actually: Entitlement.plist: ... com.apple.developer.driverkit.transport.pci I
Topic: App & System Services SubTopic: Drivers Tags:
Replies
Boosts
Views
Activity
Nov ’25
Reply to How to correctly fetch data using SwiftData
Sorry got confused with all the code. import SwiftUI import SwiftData @main struct fbla_appApp: App { var body: some Scene { WindowGroup { ContentView() } .modelContainer(for: allProfileData.self) } }
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’25
The relationship between age verification and permission kit isn't clear (IMO)
I'm trying to digest and understand the new set of APIs relating age verification that were released last week. I have say that without some cohesive overview, example app, just a simple diagram showing the relationship of everything, its not at all clear to me what's going on nor what an app developer is expected to do to use these apis (I'm a senior engineer with 15 year's iOS experience, but hey maybe I'm just a bit slow in the head). I have a few questions, but the topic of this post is what is the relationship between age verification i.e. between the declared age range/significant change and Permission Kit? The documentation for the former mentions the Significant Change API/Topic (https://developer.apple.com/news/?id=2ezb6jhj / https://developer.apple.com/documentation/PermissionKit/SignificantAppUpdateTopic). Now the Significant Change Topic is documented as being part of PermissionKit, however the documentation for that (https://developer.apple.com/documentation/permissionkit) State
Replies
1
Boosts
0
Views
216
Activity
Nov ’25
Reply to How to correctly fetch data using SwiftData
My code for the last block: import SwiftUI import SwiftData struct HomeView: View { @Query var profiledata: [allProfileData] //get all profiledata @Environment(.modelContext) private var modelContext @State private var profileImage: Image = Image(DefaultProfile) var body: some View { VStack { profileImage } .onAppear() { let fetchRequest = FetchDescriptor() let fetchedData = try? modelContext.fetch(fetchRequest) print(Fetched count: (fetchedData?.count ?? 0)) if let imageData = profiledata.first?.profileImageData, let uiImage = UIImage(data: imageData) { profileImage = Image(uiImage: uiImage) } else { profileImage = Image(DefaultProfile) } //yes, I realize that I could use profiledata.first?.profileImage but I was just checking if profileImageData would save or not } } }
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’25
Reply to Drag & Drop with view hierarchy
Finally I was able to solve this via GeometryProxy with some math. It could be hard to wrap the brain around local and global coordinates relationship.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Nov ’25
How to correctly fetch data using SwiftData
Hi there! I'm making an app that stores data for the user's profile in SwiftData. I was originally going to use UserDefaults but I thought SwiftData could save Images natively but this is not true so I really could switch back to UserDefaults and save images as Data but I'd like to try to get this to work first. So essentially I have textfields and I save the values of them through a class allProfileData. Here's the code for that: import SwiftData import SwiftUI @Model class allProfileData { var profileImageData: Data? var email: String var bio: String var username: String var profileImage: Image { if let data = profileImageData, let uiImage = UIImage(data: data) { return Image(uiImage: uiImage) } else { return Image(DefaultProfile) } } init(email:String, profileImageData: Data?, bio: String, username:String) { self.profileImageData = profileImageData self.email = email self.bio = bio self.username = username } } To save this I create a new class (I think, I'm new) and save it throu
Replies
7
Boosts
0
Views
338
Activity
Nov ’25
SwiftData Migration: Why no explicit ETL?
When I used to do Migrations, I always used ETL and then push to a dev system to review/test before going production. The migration support is SwiftData is fine for a little tweak. I might as well just just use new schema and context and write the custom code than use the SwiftData migration support.
Replies
3
Boosts
0
Views
262
Activity
Nov ’25