Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

SwiftData Unexpected type for CompositeAttribute
I'm getting SwiftData/SchemaProperty.swift:369: Fatal error: Unexpected type for CompositeAttribute CLLocationCoordinate2D in the following situation - this is simplified, but demonstrates the issue. There are a lot of posts discussing Measurements running into the same issue, and the recommended fix is to turn the Measurement (or CLLocationCoordinate2D in this example) into a computed property and generate it on the fly. I'm trying to cache instances of CLLocationCoordinate2D, rather than creating new ones every time a View renders, so those work arounds don't work around. The SwiftData docs seem to indicate that this should be possible. Can anyone recommend a fix? Thanks in advance. import SwiftData import MapKit @Model final class foo : Codable { var bar: SomeStruct init( bar: SomeStruct ) { self.bar = bar } enum CodingKeys : CodingKey { case bar } init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.bar = try container.decode(
4
0
1.5k
Dec ’23
Reply to How are child processes sandboxed?
Hello, I have a follow up question. It is by design the sandbox gets inherited when running a command line tool using the Process.run() from an application signed by a different Team ID? Eg. the PowerPoint app authored by the Team ID UBF8T346G9 runs a tool signed by Team ID 44X73QA89R (a different developer team) and the tools inherit's the PowerPoint app's sandbox.
Topic: Privacy & Security SubTopic: General Tags:
May ’25
Multiple entities relationship with shop customers vehicle
How can I connect multiple identities with no common sharing fields between them into one object? Also what would be the relationship between these identities? Do I need to add a field called ID for each like CUSTID or ShopID or whatever to my struct that I built? Also I want to put them all in separate array obj for example customer struct with its properties will be stored in customer = [Customer] () How do I store and access them from a custom cell with label and textfield in a tableviewcontroller so that they all attach together as one object with shop and with techninfo shopinfo and with inspectionitems. I am a new programmer trying to do my project on my own and my concept need some clarification so I can move forward with it and get this app done. Please help if you can ...any help will be appreciated.
0
0
335
Oct ’21
SwiftData Configurations for Private and Public CloudKit
I did manage to save my Entities to CloudKit with SwiftData but the default database is the private database. I need to store some Entities in the private and other Entities in the public CloudKit database. How do I manage that with SwiftData? With CoreData I always used different configurations for both private and public and added the entities to one or the other.
6
0
6.7k
Jun ’23
Compound AND predicate for many to many relationship using SUBQUERY
I have an entity A with a many to many relationship events with entity Event. Entity Event has an attribute eventName.I want to be able to fetch all entity As that have a given set of Event entitys that match the entityName selected by the user. For an ANY fetch, a compound OR predicate works fine. But for an ALL fetch (where only entity As that have ALL of the user chosen events will be fetched) the compound AND predicate returns a nil!I was told that I would have to use subqueries. My deliema is that I am having a hard time figuring out how to form a subquery string.The format is as follows...SUBQUERY(collection_expression, variable_expression, predicate);I'll have the eventName string selected by the user so that is dynamic. So what should my subquery look like if I want to use the LIKE[d] operator?the collection_expression would be the relationship events if i am not wrong?kindly help me out with this.thankyou.
8
0
2.5k
Jun ’15
RealityView Not Refreshing With SwiftData
Hi, I am trying to update what entities are visible in my RealityView. After the SwiftData set is updated, I have to restart the app for it to appear in the RealityView. Also, the RealityView does not close when I move to a different tab. It keeps everything on and tracking, leaving the model in the same location I left it. import SwiftUI import RealityKit import MountainLake import SwiftData struct RealityLakeView: View { @Environment(.modelContext) private var context @Query private var items: [Item] var body: some View { RealityView { content in print(View Loaded) let lakeScene = try? await Entity(named: Lake, in: mountainLakeBundle) let anchor = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2(0.2, 0.2))) @MainActor func addEntity(name: String) { if let lakeEntity = lakeScene?.findEntity(named: name) { // Add the Cube_1 entity to the RealityView anchor.addChild(lakeEntity) } else { print(name + entity not found in the Lake scene.) } } addEntity(name: Island) fo
3
0
556
Jan ’25
Regarding the Preview issue with SwiftData
I referred to the code provided in the article Adding and Editing Persistent Data in Your App in the SwiftData documentation and tested the /PreviewHelper approach. I found that if a model class contains a property of a struct, and that struct includes a Set property or an Array property, the Preview would throw an error. Here is an example of the model: @Model class Book { // ... var someStruct: SomeStruct // ... } struct SomeStruct: Codable { // ... var someCollection: Set // ... } In actuality, this model can run and store data without any issues, but it fails to run in the Preview. Is there a problem with the implementation of this Preview or is there any other reason? Are there better ways to perform Preview in SwiftData?
1
0
721
Apr ’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
615
Feb ’24
SwiftData and async functions
Hello, I recently published an app that uses Swift Data as its primary data storage. The app uses concurrency, background threads, async await, and BLE communication. Sadly, I see my app incurs many fringe crashes, involving EXC_BAD_ACCESS, KERN_INVALID_ADDRESS, EXC_BREAKPOINT, etc. I followed these guidelines: One ModelContainer that is stored as a global variable and used throughout. ModelContexts are created separately for each task, changes are saved manually, and models are not passed around. Threads with different ModelContexts might manipulate and/or read the same data simultaneously. I was under the impression this meets the usage requirements. I suspect perhaps the issue lies in my usage of contexts in a single await function, that might be paused and resumed on a different thread (although same execution path). Is that the case? If so, how should SwiftData be used in async scopes? Is there anything else particularly wrong in my approach?
4
0
1.3k
Dec ’24
SwiftData Unexpected type for CompositeAttribute
I'm getting SwiftData/SchemaProperty.swift:369: Fatal error: Unexpected type for CompositeAttribute CLLocationCoordinate2D in the following situation - this is simplified, but demonstrates the issue. There are a lot of posts discussing Measurements running into the same issue, and the recommended fix is to turn the Measurement (or CLLocationCoordinate2D in this example) into a computed property and generate it on the fly. I'm trying to cache instances of CLLocationCoordinate2D, rather than creating new ones every time a View renders, so those work arounds don't work around. The SwiftData docs seem to indicate that this should be possible. Can anyone recommend a fix? Thanks in advance. import SwiftData import MapKit @Model final class foo : Codable { var bar: SomeStruct init( bar: SomeStruct ) { self.bar = bar } enum CodingKeys : CodingKey { case bar } init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.bar = try container.decode(
Replies
4
Boosts
0
Views
1.5k
Activity
Dec ’23
Reply to How are child processes sandboxed?
Hello, I have a follow up question. It is by design the sandbox gets inherited when running a command line tool using the Process.run() from an application signed by a different Team ID? Eg. the PowerPoint app authored by the Team ID UBF8T346G9 runs a tool signed by Team ID 44X73QA89R (a different developer team) and the tools inherit's the PowerPoint app's sandbox.
Topic: Privacy & Security SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’25
Multiple entities relationship with shop customers vehicle
How can I connect multiple identities with no common sharing fields between them into one object? Also what would be the relationship between these identities? Do I need to add a field called ID for each like CUSTID or ShopID or whatever to my struct that I built? Also I want to put them all in separate array obj for example customer struct with its properties will be stored in customer = [Customer] () How do I store and access them from a custom cell with label and textfield in a tableviewcontroller so that they all attach together as one object with shop and with techninfo shopinfo and with inspectionitems. I am a new programmer trying to do my project on my own and my concept need some clarification so I can move forward with it and get this app done. Please help if you can ...any help will be appreciated.
Replies
0
Boosts
0
Views
335
Activity
Oct ’21
SwiftData Configurations for Private and Public CloudKit
I did manage to save my Entities to CloudKit with SwiftData but the default database is the private database. I need to store some Entities in the private and other Entities in the public CloudKit database. How do I manage that with SwiftData? With CoreData I always used different configurations for both private and public and added the entities to one or the other.
Replies
6
Boosts
0
Views
6.7k
Activity
Jun ’23
Compound AND predicate for many to many relationship using SUBQUERY
I have an entity A with a many to many relationship events with entity Event. Entity Event has an attribute eventName.I want to be able to fetch all entity As that have a given set of Event entitys that match the entityName selected by the user. For an ANY fetch, a compound OR predicate works fine. But for an ALL fetch (where only entity As that have ALL of the user chosen events will be fetched) the compound AND predicate returns a nil!I was told that I would have to use subqueries. My deliema is that I am having a hard time figuring out how to form a subquery string.The format is as follows...SUBQUERY(collection_expression, variable_expression, predicate);I'll have the eventName string selected by the user so that is dynamic. So what should my subquery look like if I want to use the LIKE[d] operator?the collection_expression would be the relationship events if i am not wrong?kindly help me out with this.thankyou.
Replies
8
Boosts
0
Views
2.5k
Activity
Jun ’15
SwiftData Model Spotlight attribute
I'm trying to add spotlight support to my app using SwiftData, I've seen this attribute on the apple documentation, but still is not working, did someone was able to make it work?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
0
Boosts
0
Views
271
Activity
Aug ’24
Reply to Instance member cannot be used on type in ARKitVision example
I don't understand, the class inherits from UIViewController and yet Xcode does not see the 'children' var as being available. Why would that be the case?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’18
RealityView Not Refreshing With SwiftData
Hi, I am trying to update what entities are visible in my RealityView. After the SwiftData set is updated, I have to restart the app for it to appear in the RealityView. Also, the RealityView does not close when I move to a different tab. It keeps everything on and tracking, leaving the model in the same location I left it. import SwiftUI import RealityKit import MountainLake import SwiftData struct RealityLakeView: View { @Environment(.modelContext) private var context @Query private var items: [Item] var body: some View { RealityView { content in print(View Loaded) let lakeScene = try? await Entity(named: Lake, in: mountainLakeBundle) let anchor = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2(0.2, 0.2))) @MainActor func addEntity(name: String) { if let lakeEntity = lakeScene?.findEntity(named: name) { // Add the Cube_1 entity to the RealityView anchor.addChild(lakeEntity) } else { print(name + entity not found in the Lake scene.) } } addEntity(name: Island) fo
Replies
3
Boosts
0
Views
556
Activity
Jan ’25
Regarding the Preview issue with SwiftData
I referred to the code provided in the article Adding and Editing Persistent Data in Your App in the SwiftData documentation and tested the /PreviewHelper approach. I found that if a model class contains a property of a struct, and that struct includes a Set property or an Array property, the Preview would throw an error. Here is an example of the model: @Model class Book { // ... var someStruct: SomeStruct // ... } struct SomeStruct: Codable { // ... var someCollection: Set // ... } In actuality, this model can run and store data without any issues, but it fails to run in the Preview. Is there a problem with the implementation of this Preview or is there any other reason? Are there better ways to perform Preview in SwiftData?
Replies
1
Boosts
0
Views
721
Activity
Apr ’24
Reply to Covariant and contravariant generic type parameters
I still don't get why use generics here instead of the perfectly fine working inheritance...
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to How to focus a sprite in SKView?
Thank you for replying.I notice that the SKView is inherited from UIView, therefore it should support focus. Right?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Sep ’15
Reply to Infinite loop from didSet in property
I started seeing this in Xcode 9.3!I fixed it by making Protocol inherit `class`, but it is very annoying.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Apr ’18
Reply to Why UICollectionViewDiffableDataSource compares items by reference
Hashable inherits - https://developer.apple.com/documentation/swift/hashable from Equatable, so no need
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Apr ’21
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?
Replies
0
Boosts
0
Views
615
Activity
Feb ’24
SwiftData and async functions
Hello, I recently published an app that uses Swift Data as its primary data storage. The app uses concurrency, background threads, async await, and BLE communication. Sadly, I see my app incurs many fringe crashes, involving EXC_BAD_ACCESS, KERN_INVALID_ADDRESS, EXC_BREAKPOINT, etc. I followed these guidelines: One ModelContainer that is stored as a global variable and used throughout. ModelContexts are created separately for each task, changes are saved manually, and models are not passed around. Threads with different ModelContexts might manipulate and/or read the same data simultaneously. I was under the impression this meets the usage requirements. I suspect perhaps the issue lies in my usage of contexts in a single await function, that might be paused and resumed on a different thread (although same execution path). Is that the case? If so, how should SwiftData be used in async scopes? Is there anything else particularly wrong in my approach?
Replies
4
Boosts
0
Views
1.3k
Activity
Dec ’24