Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

SwiftData ModelContainer can not be created in iOS 17.4 Beta
I have an app in the app store which is working fine. Some users reported that they have app crashing when they are using iOS 17.4 beta. I could recreate the issue and it is happening when ModelContainer is crerated. This code.. do { let configuration = ModelConfiguration(for: MyTodo.self, isStoredInMemoryOnly: false) modelContainer = try ModelContainer(for: MyTodo.self, configurations: configuration) } catch { fatalError(Failed to load model container.(error)) } is throwing this error message: Fatal error: Failed to load model container.SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer)
10
0
4.9k
Mar ’24
Reply to Autogenerated UI Test Runner Blocked By Local Network Permission Prompt
We only support macOS virtualisation on Mac hardware. Are you planning to run your own hardware? Or are you planning to build your CI system on top of a virtualisation service from another company? And if you plan to run your own hardware, roughly how many hosts are we talking about? We run 80+ physical Mac Mini's for our CI/CD needs. We're attempting to build virtualization on top of these machines to make it easier to restore the CI environment to a known, good state after runs. Today we register each machine in the developer portal and integrate it into our provisioning profiles. However, with VM through the Virtaulization.framework in order to reset to a clean state we have to boot a new VM, which gives us a new UDID. Registering each one of these would easily blow past the registered device limits stipulated in https://developer.apple.com/help/account/devices/devices-overview. I’d like to clarify my understanding of this setup. Specifically, is the ↳ symbol meant to represent a dependency? Or a flow of c
Jun ’25
ViewThatFits and Text Truncation
I'm using ViewThatFits to handle different screen sizes as well as the orientation of the phone. Essentially, I have a smaller view that should only be used in portrait mode on the phone and a larger view that should be used in every other instance. The issue is that both of those views have a Text view that is bound to a String within a SwiftData model. If the String is too long the ViewThatFits considers that when choosing the appropriate subview. This results in a list of items where most items use one view while one or more may use the other view. It would be great if there was a modifier that could be applied to the Text view that resulted in the ViewThatFits ignoring it when determining the appropriate subview. Until such a modifier is available, has anyone come up with creative ways around this?
1
0
108
Jun ’25
SwiftData SchemaMigrationPlan and VersionedSchema not Sendable?
I've just tried to update a project that uses SwiftData to Swift 6 using Xcode 16 beta 1, and it's not working due to missing Sendable conformance on a couple of types (MigrationStage and Schema.Version): struct LocationsMigrationPlan: SchemaMigrationPlan { static let schemas: [VersionedSchema.Type] = [LocationsVersionedSchema.self] static let stages: [MigrationStage] = [] } struct LocationsVersionedSchema: VersionedSchema { static let models: [any PersistentModel.Type] = [ Location.self ] static let versionIdentifier = Schema.Version(1, 0, 0) } This code results in the following errors: error: static property 'stages' is not concurrency-safe because non-'Sendable' type '[MigrationStage]' may have shared mutable state static let stages: [MigrationStage] = [] ^ error: static property 'versionIdentifier' is not concurrency-safe because non-'Sendable' type 'Schema.Version' may have shared mutable state static let versionIdentifier = Schema.Version(1, 0, 0) ^ Am I missing something, or is this a bug in t
3
0
1.9k
Nov ’24
Reply to Autogenerated UI Test Runner Blocked By Local Network Permission Prompt
[quote='843518022, brian-bcny, /thread/787469?answerId=843518022#843518022, /profile/brian-bcny'] I feel like I'm talking to a legend! [/quote] Yeah, I just wish I had better answers for you )-: Let’s start with the VM side of this. There’s been a bit of back’n’forth about using restricted entitlements in a VM. If you’re curious, I just updated this thread with a short history and the less-than-ideal current state of affairs. However, for the sake of this discussion let’s assume that’s been sorted out. Assuming that fix, the next roadblock is this: [quote='843518022, brian-bcny, /thread/787469?answerId=843518022#843518022, /profile/brian-bcny'] a fresh VM with a new UDID we'd easily blow through the registered device limits in the developer portal in no time [/quote] Indeed. There are a bunch of potential pitfalls here. There might be a way to skirt around them but I’d like to clarify one point with you. We only support macOS virtualisation on Mac hardware. Are you planning to run your own hardware? Or are yo
Jun ’25
Reply to @ModelActor with default actor isolation = MainActor
If you set the Default Actor Isolation to MainActor, which is the default value of a new project after Swift 6.2, the compiler will assume that your code runs on the main actor, unless you say otherwise. In the case you described, where your SwiftData models can run in a model actor (@ModelActor), you should explicitly annotate the model classes with nonisolated, as shown below: @Model nonisolated class MyCoolModel { var timestamp: Date ... } A model actor is an actor that has its own model context, and so you can use it as a normal actor, and mark its functions with nonisolated, if needed: @ModelActor actor MyTestModelActor { func updateTimestamp(identifier: PersistentIdentifier) throws { guard let model = modelContext.model(for: identifier) as? MyCoolModel else { return } model.timestamp = Date() try modelContext.save() } nonisolated func doSomethingNonisolated(...) {...} } Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jun ’25
SwiftData: filtering against an array of PersistentIdentifiers
I would like to have a SwiftData predicate that filters against an array of PersistentIdentifiers. A trivial use case could filtering Posts by one or more Categories. This sounds like something that must be trivial to do. When doing the following, however: let categoryIds: [PersistentIdentifier] = categoryFilter.map { $0.id } let pred = #Predicate { if let catId = $0.category?.persistentModelID { return categoryIds.contains(catId) } else { return false } } The code compiles, but produces the following runtime exception (XCode 26 beta, iOS 26 simulator): 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (TERNARY(item != nil, item, nil) IN {}) (bad LHS)' Strangely, the same code works if the array to filter against is an array of a primitive type, e.g. String or Int. What is going wrong here and what could be a possible workaround?
3
0
134
Jun ’25
Reply to SwiftData: filtering against an array of PersistentIdentifiers
The PersistentIdentifier is basically an abstraction over the DB primary key, it's a Struct consisting of the storeId, the entity name, and the primary key. You can normally use PersistentIdentifiers in SwiftData predicates, so you can do { post in post.persistentModelID == aModelIdIAmLookingFor } I cannot use the Category directly in the predicate, since it is an Optional. SwiftData predicates have problems comparing Optionals, such things only tend to work if you provide a default value before the comparison, e.g. (optionalString ?? ) == someNonOptionalString. After some debugging, I have discovered that what is causing the issue, is not the PersistentIdentifier itself, but the if-let clause with the PersistentIdentifier. Thus, performing the optional binding with Category instead of the PersistentIdentifier makes it work: if let cat = $0.category { return categoryIds.contains(cat.persistentModelID) }
Jun ’25
Reply to SwiftData Models not working after updating to macOS 26
The error message indicates that your model uses a non-codable type, which is not allowed in SwiftData, but if that is the case, your code shouldn't work in the previous system versions. It's hard to say anything more than that without looking into your schema. If you can provide a minimal project that contains only the relevant code, with detailed steps to reproduce the issue, I'll be happy to take a closer look. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jun ’25
Reply to Can Game Mode be activated when a child (Java) process's window is fullscreened?
Thanks for that. I asked over in the privacy/security section of the forums and the verdict seems to be that these types of properties don't get inherited because that's not how it works. However I was given the suggestion to possibly change the Java executable's Info.plist instead, although trying this didn't seem to successfully get Game Mode to activate (tested on macOS 15.5 (24F74)), unfortunately. (Is that expected behavior?) So looks like this won't work, as you thought. Though it is strange that Game Mode does work with apps like the Minecraft official launcher which use this architecture, which seems to imply there is some way this is done. I can't find a code-level way to implement this, but I do see that: If the launcher app is opened from Steam and then the launcher app opens the Java game, then fullscreening the Java game does activate Game Mode. So seems like children of Steam have some kind of special handling, though I'm not sure if that's the doing of Steam or the OS. If you change an
Topic: Graphics & Games SubTopic: General Tags:
Jun ’25
Can child processes inherit Info.plist properties of a parent app (such as LSSupportsGameMode)?
My high-level goal is to add support for Game Mode in a Java game, which launches via a macOS launcher app that runs the actual java game as a separate process (e.g. using the java command line tool). I asked this over in the Graphics & Games section and was told this, which is why I'm reposting this here. I'm uncertain how to speak to CLI tools and Java games launched from a macOS app. These sound like security and sandboxing questions which we recommend you ask about in those sections of the forums. The system seems to decide whether to enable Game Mode based on values in the Info.plist (e.g. for LSApplicationCategoryType and GCSupportsGameMode). However, the child process can't seem to see these values. Is there a way to change that? (The rest of this post is copied from my other forums post to provide additional context.) Imagine a native macOS app that acts as a launcher for a Java game.** For example, the launcher app might use the Swift Process API or a similar method to run the java command line t
3
0
378
Jun ’25
Reply to Can child processes inherit Info.plist properties of a parent app (such as LSSupportsGameMode)?
[quote='787774021, kthchew, /thread/787774, /profile/kthchew'] Can child processes inherit Info.plist properties of a parent app … ? [/quote] No. Info.plist properties are set in one of two ways: If the code is bundled, there’s an Info.plist file in that bundle. For a standalone executable, you can embed an Info.plist in the __TEXT / __info_plist section of the executable. Unlike entitlements, these properties are not directly tied to the process. Rather, some code in the system has to consult the properties. This is common done from within the process — code in a system framework gets the current processe’s bundle and fetches properties from that — but it can also be done from outside. Given that design, there’s no inheritance. If you want something to be effective, you have set it on that program’s Info.plist. And that makes the Java thing tricky because you don’t control it’s Info.plist. Having said that, Java isn’t built in to the system, so you could potentially build your own copy with
Topic: Privacy & Security SubTopic: General Tags:
Jun ’25
Reply to Old CloudKit Data Repopulating after a Local Reset
Since we are only configuring only 1 zone and the objective is to delete every record, would using modifyRecordZones(saving:deleting:) to simply delete the zone then start our app from the beginning have the same outcome ... That will work, if there is no synchronization activity happens in between the deletions of the local data and the remote data, which you can probably achieve by releasing the model container immediately after deleting the local data. But again, SwiftData doesn't expose any CloudKit thing, and so I am not quite sure if that is a guarantee. (and be more Swifty?) The APIs I mentioned have the Swift version. It seems that the documentation is broken, and so I can only find the links to the objective C version. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Jun ’25
SwiftData ModelContainer can not be created in iOS 17.4 Beta
I have an app in the app store which is working fine. Some users reported that they have app crashing when they are using iOS 17.4 beta. I could recreate the issue and it is happening when ModelContainer is crerated. This code.. do { let configuration = ModelConfiguration(for: MyTodo.self, isStoredInMemoryOnly: false) modelContainer = try ModelContainer(for: MyTodo.self, configurations: configuration) } catch { fatalError(Failed to load model container.(error)) } is throwing this error message: Fatal error: Failed to load model container.SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer)
Replies
10
Boosts
0
Views
4.9k
Activity
Mar ’24
Reply to defaultIsolation option and Core Data
I think what you did - adding nonisolated - is correct. Also needed for SwiftData and at-ModelActor.
Replies
Boosts
Views
Activity
Jun ’25
Reply to Autogenerated UI Test Runner Blocked By Local Network Permission Prompt
We only support macOS virtualisation on Mac hardware. Are you planning to run your own hardware? Or are you planning to build your CI system on top of a virtualisation service from another company? And if you plan to run your own hardware, roughly how many hosts are we talking about? We run 80+ physical Mac Mini's for our CI/CD needs. We're attempting to build virtualization on top of these machines to make it easier to restore the CI environment to a known, good state after runs. Today we register each machine in the developer portal and integrate it into our provisioning profiles. However, with VM through the Virtaulization.framework in order to reset to a clean state we have to boot a new VM, which gives us a new UDID. Registering each one of these would easily blow past the registered device limits stipulated in https://developer.apple.com/help/account/devices/devices-overview. I’d like to clarify my understanding of this setup. Specifically, is the ↳ symbol meant to represent a dependency? Or a flow of c
Replies
Boosts
Views
Activity
Jun ’25
ViewThatFits and Text Truncation
I'm using ViewThatFits to handle different screen sizes as well as the orientation of the phone. Essentially, I have a smaller view that should only be used in portrait mode on the phone and a larger view that should be used in every other instance. The issue is that both of those views have a Text view that is bound to a String within a SwiftData model. If the String is too long the ViewThatFits considers that when choosing the appropriate subview. This results in a list of items where most items use one view while one or more may use the other view. It would be great if there was a modifier that could be applied to the Text view that resulted in the ViewThatFits ignoring it when determining the appropriate subview. Until such a modifier is available, has anyone come up with creative ways around this?
Replies
1
Boosts
0
Views
108
Activity
Jun ’25
SwiftData SchemaMigrationPlan and VersionedSchema not Sendable?
I've just tried to update a project that uses SwiftData to Swift 6 using Xcode 16 beta 1, and it's not working due to missing Sendable conformance on a couple of types (MigrationStage and Schema.Version): struct LocationsMigrationPlan: SchemaMigrationPlan { static let schemas: [VersionedSchema.Type] = [LocationsVersionedSchema.self] static let stages: [MigrationStage] = [] } struct LocationsVersionedSchema: VersionedSchema { static let models: [any PersistentModel.Type] = [ Location.self ] static let versionIdentifier = Schema.Version(1, 0, 0) } This code results in the following errors: error: static property 'stages' is not concurrency-safe because non-'Sendable' type '[MigrationStage]' may have shared mutable state static let stages: [MigrationStage] = [] ^ error: static property 'versionIdentifier' is not concurrency-safe because non-'Sendable' type 'Schema.Version' may have shared mutable state static let versionIdentifier = Schema.Version(1, 0, 0) ^ Am I missing something, or is this a bug in t
Replies
3
Boosts
0
Views
1.9k
Activity
Nov ’24
Reply to SwiftData SchemaMigrationPlan and VersionedSchema not Sendable?
This looks like it's fixed in iOS 26 Beta 1. If you use the extension workaround above you get a warning Conformance of 'Schema.Version' to protocol 'Sendable' was already stated in the type's module 'SwiftData' 'Schema.Version' declares conformance to protocol 'Sendable' here (SwiftData.Schema.Version)
Replies
Boosts
Views
Activity
Jun ’25
Reply to Autogenerated UI Test Runner Blocked By Local Network Permission Prompt
[quote='843518022, brian-bcny, /thread/787469?answerId=843518022#843518022, /profile/brian-bcny'] I feel like I'm talking to a legend! [/quote] Yeah, I just wish I had better answers for you )-: Let’s start with the VM side of this. There’s been a bit of back’n’forth about using restricted entitlements in a VM. If you’re curious, I just updated this thread with a short history and the less-than-ideal current state of affairs. However, for the sake of this discussion let’s assume that’s been sorted out. Assuming that fix, the next roadblock is this: [quote='843518022, brian-bcny, /thread/787469?answerId=843518022#843518022, /profile/brian-bcny'] a fresh VM with a new UDID we'd easily blow through the registered device limits in the developer portal in no time [/quote] Indeed. There are a bunch of potential pitfalls here. There might be a way to skirt around them but I’d like to clarify one point with you. We only support macOS virtualisation on Mac hardware. Are you planning to run your own hardware? Or are yo
Replies
Boosts
Views
Activity
Jun ’25
Reply to @ModelActor with default actor isolation = MainActor
If you set the Default Actor Isolation to MainActor, which is the default value of a new project after Swift 6.2, the compiler will assume that your code runs on the main actor, unless you say otherwise. In the case you described, where your SwiftData models can run in a model actor (@ModelActor), you should explicitly annotate the model classes with nonisolated, as shown below: @Model nonisolated class MyCoolModel { var timestamp: Date ... } A model actor is an actor that has its own model context, and so you can use it as a normal actor, and mark its functions with nonisolated, if needed: @ModelActor actor MyTestModelActor { func updateTimestamp(identifier: PersistentIdentifier) throws { guard let model = modelContext.model(for: identifier) as? MyCoolModel else { return } model.timestamp = Date() try modelContext.save() } nonisolated func doSomethingNonisolated(...) {...} } Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Jun ’25
SwiftData: filtering against an array of PersistentIdentifiers
I would like to have a SwiftData predicate that filters against an array of PersistentIdentifiers. A trivial use case could filtering Posts by one or more Categories. This sounds like something that must be trivial to do. When doing the following, however: let categoryIds: [PersistentIdentifier] = categoryFilter.map { $0.id } let pred = #Predicate { if let catId = $0.category?.persistentModelID { return categoryIds.contains(catId) } else { return false } } The code compiles, but produces the following runtime exception (XCode 26 beta, iOS 26 simulator): 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (TERNARY(item != nil, item, nil) IN {}) (bad LHS)' Strangely, the same code works if the array to filter against is an array of a primitive type, e.g. String or Int. What is going wrong here and what could be a possible workaround?
Replies
3
Boosts
0
Views
134
Activity
Jun ’25
Reply to SwiftData: filtering against an array of PersistentIdentifiers
The PersistentIdentifier is basically an abstraction over the DB primary key, it's a Struct consisting of the storeId, the entity name, and the primary key. You can normally use PersistentIdentifiers in SwiftData predicates, so you can do { post in post.persistentModelID == aModelIdIAmLookingFor } I cannot use the Category directly in the predicate, since it is an Optional. SwiftData predicates have problems comparing Optionals, such things only tend to work if you provide a default value before the comparison, e.g. (optionalString ?? ) == someNonOptionalString. After some debugging, I have discovered that what is causing the issue, is not the PersistentIdentifier itself, but the if-let clause with the PersistentIdentifier. Thus, performing the optional binding with Category instead of the PersistentIdentifier makes it work: if let cat = $0.category { return categoryIds.contains(cat.persistentModelID) }
Replies
Boosts
Views
Activity
Jun ’25
Reply to SwiftData Models not working after updating to macOS 26
The error message indicates that your model uses a non-codable type, which is not allowed in SwiftData, but if that is the case, your code shouldn't work in the previous system versions. It's hard to say anything more than that without looking into your schema. If you can provide a minimal project that contains only the relevant code, with detailed steps to reproduce the issue, I'll be happy to take a closer look. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Jun ’25
Reply to Can Game Mode be activated when a child (Java) process's window is fullscreened?
Thanks for that. I asked over in the privacy/security section of the forums and the verdict seems to be that these types of properties don't get inherited because that's not how it works. However I was given the suggestion to possibly change the Java executable's Info.plist instead, although trying this didn't seem to successfully get Game Mode to activate (tested on macOS 15.5 (24F74)), unfortunately. (Is that expected behavior?) So looks like this won't work, as you thought. Though it is strange that Game Mode does work with apps like the Minecraft official launcher which use this architecture, which seems to imply there is some way this is done. I can't find a code-level way to implement this, but I do see that: If the launcher app is opened from Steam and then the launcher app opens the Java game, then fullscreening the Java game does activate Game Mode. So seems like children of Steam have some kind of special handling, though I'm not sure if that's the doing of Steam or the OS. If you change an
Topic: Graphics & Games SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’25
Can child processes inherit Info.plist properties of a parent app (such as LSSupportsGameMode)?
My high-level goal is to add support for Game Mode in a Java game, which launches via a macOS launcher app that runs the actual java game as a separate process (e.g. using the java command line tool). I asked this over in the Graphics & Games section and was told this, which is why I'm reposting this here. I'm uncertain how to speak to CLI tools and Java games launched from a macOS app. These sound like security and sandboxing questions which we recommend you ask about in those sections of the forums. The system seems to decide whether to enable Game Mode based on values in the Info.plist (e.g. for LSApplicationCategoryType and GCSupportsGameMode). However, the child process can't seem to see these values. Is there a way to change that? (The rest of this post is copied from my other forums post to provide additional context.) Imagine a native macOS app that acts as a launcher for a Java game.** For example, the launcher app might use the Swift Process API or a similar method to run the java command line t
Replies
3
Boosts
0
Views
378
Activity
Jun ’25
Reply to Can child processes inherit Info.plist properties of a parent app (such as LSSupportsGameMode)?
[quote='787774021, kthchew, /thread/787774, /profile/kthchew'] Can child processes inherit Info.plist properties of a parent app … ? [/quote] No. Info.plist properties are set in one of two ways: If the code is bundled, there’s an Info.plist file in that bundle. For a standalone executable, you can embed an Info.plist in the __TEXT / __info_plist section of the executable. Unlike entitlements, these properties are not directly tied to the process. Rather, some code in the system has to consult the properties. This is common done from within the process — code in a system framework gets the current processe’s bundle and fetches properties from that — but it can also be done from outside. Given that design, there’s no inheritance. If you want something to be effective, you have set it on that program’s Info.plist. And that makes the Java thing tricky because you don’t control it’s Info.plist. Having said that, Java isn’t built in to the system, so you could potentially build your own copy with
Topic: Privacy & Security SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’25
Reply to Old CloudKit Data Repopulating after a Local Reset
Since we are only configuring only 1 zone and the objective is to delete every record, would using modifyRecordZones(saving:deleting:) to simply delete the zone then start our app from the beginning have the same outcome ... That will work, if there is no synchronization activity happens in between the deletions of the local data and the remote data, which you can probably achieve by releasing the model container immediately after deleting the local data. But again, SwiftData doesn't expose any CloudKit thing, and so I am not quite sure if that is a guarantee. (and be more Swifty?) The APIs I mentioned have the Swift version. It seems that the documentation is broken, and so I can only find the links to the objective C version. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Jun ’25