Search results for

“SwiftData inheritance relationship”

4,981 results found

Post

Replies

Boosts

Views

Activity

SwiftUI and SwiftData @Query
Hey everyone, I’m relatively new to SwiftUI and iOS development, having started earlier this year, and I’m working on a Notes app using SwiftData. I’ve run into some issues when dealing with nested views. In my app, I’m using a SwiftData @Query in a parent view and then passing the model objects down the view tree. However, I’m frequently encountering errors such as “No container found” or similar. To work around this, I’ve tried having the child views perform their own SwiftData @Query, with the parent view passing a string identifier to the child views. This approach has helped somewhat, but I’m still not entirely sure how to properly manage UI updates. Additionally, I’ve noticed that turning on iCloud syncing seems to have made the problem worse. The errors have become more frequent, and it’s unclear to me how to handle these situations effectively. Could someone explain the best practices for handling SwiftData queries in nested SwiftUI views, especially with iCloud syn
1
0
1.5k
Aug ’24
Files & Folders not inheriting ACL permissions when opened, modified or created in shared SMB in Big Sur
Fishing for an answer... Trying to transfer (upgrade) a shared file server to a new Mac Mini M1 on Big Sur 1- File sharing is gone from Mac Os Server App So no more Make Inherited Entries Explicit. option! 2- I know I have to change the ACL Value of all those files different groups have access to different files.... 4- I have found this here https://discussions.apple.com/thread/250537136 chmod =a# 0 thegroup allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit BadShare Would love to chat with Strontium90 to help me understand And trying to apply it in Big Sur and it's not working. Here is what I have tried: Ex: I created a group name: test created a test folder named: testfld I used Dropbox to back all the files... chmod =a# 0 “test allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit /Users/server/Dropbox/BigBackUp/Tes
1
0
2.5k
Jul ’21
When will SwiftData support UInt64?
According to my experiments SwiftData does not work with model attributes of primitive type UInt64. More precisely, it crashes in the getter of a UInt64 attribute invoked on an object fetched from the data store. With Core Data persistent UInt64 attributes are not a problem. Does anyone know whether SwiftData will ever support UInt64?
2
0
437
Mar ’24
Access SwiftData in Widgets
How do I access the SwiftData ModelContainer of my app inside the widget extension? Following the guide to add a Widget Extension I’ve added the necessary target to my project and enabled App Groups. I’ve seen that the Backyard Birds example code offers an example how to build this, but it encapsulates the SwiftData handling in a separate app package. Therefore the example simply points to the app package. Though, in my case I don’t host my SwiftData in an external app package, but simply inside the regular app target. So, my question is how and at which point in code do I need to access the ModelContainer?
1
0
2.2k
Jun ’24
Reply to SwiftData on iOS 18 extreme memory use
Ziqiao, thanks for the fetchCount workaround. Unfortunately I've found another case. Simply iterating over a @Query with ForEach causes the same problem. No call to count. Your suggestion to make large items in externalStorage reference instead does help in this case too. But it points to a serious problem in SwiftData, where Query macros become useless in non-trivial apps. (I'm pretty sure that the problem does not happen when iterating or counting an array representing a one-to-many relationship. Hard to be sure because I can't get the app running well enough to exercise in iOS 18) I do hope that it's fixable, because this is not how SwiftData is supposed to work, and everything works fine on iOS 17.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24
Does SwiftData require paging?
Hello. I'm going to create an app that supports purchase records. SwiftData was used to implement storage, backup, and restoration functions at once. One question is whether paging is necessary. When you receive data from a server, you usually implement paging to send and receive data efficiently. In the case of Realm, I know that it uses Lazy data, so I know that there is no need for paging. What about SwiftData? Can the number of data affect performance??
0
0
528
Jul ’24
SwiftData looses attribute when restarting app
I'm trying to archive some data in my SwiftUI app, using SwiftData. I implemented a Archive Model: import Foundation import SwiftData @Model class ArchiveData { let archiveName: String let archiveDate: Date @Relationship(.cascade) var items: [Item] init(archiveName: String, archiveDate: Date, items: [Item]) { self.archiveName = archiveName self.archiveDate = archiveDate self.items = items } } Then, I'm adding the data to the context: let newArchive = ArchiveData(archiveName: name, archiveDate: Date.now, items: items) context.insert(newArchive) I can then display the archived data in a separate view. But when I restart the app, the items array of ArchiveData is empty. I couldn't find out, where I made a mistake. Can anyone help me?
1
0
579
Jun ’23
Can't query for the existence of an optional to-one relationship?
Hi, say in my model I have members and each member optionally can have a relationship to a Club. So the relationship in the Member entity would be modelled like so: @Relationship(.nullify, inverse: Club.members) var club: Club? Now I would like to fetch al Members with no Club relationship. I would assume that this would work with a predicate like this: let noClubPred = #Predicate { member in member.club == nil } Unfortunately this gives me the following error when compiling: Generic parameter 'RHS' could not be inferred. Has anybody an idea how to phrase this predicate correctly, or is this a beta issue and it should actually work? Thank you! Cheers, Michael
2
0
1.3k
Jul ’23
Get a Catalog Playlist's Relationship Directly by Name
Hi there! I am trying to map the Apple Music API endpoints to MusicKit. For example, I am looking at the catalog playlist endpoints. To get a catalog playlist by its identifier, it is: let request = MusicCatalogResourceRequest(matching: .id, equalTo: pl.f4d106fed2bd41149aaacabb233eb5eb) let response = try await request.response() print(response.items) For multiple identifiers, it is: let request = MusicCatalogResourceRequest(matching: .id, memberOf: [pl.f4d106fed2bd41149aaacabb233eb5eb, pl.4b364b8b182f4115acbf6deb83bd5222]) let response = try await request.response() print(response.items) To get its relationship like more by curator and featured artists, I can set the properties: var request = MusicCatalogResourceRequest(matching: .id, equalTo: pl.f4d106fed2bd41149aaacabb233eb5eb) request.properties = [.featuredArtists, .moreByCurator, .tracks] let response = try await request.response() print(response.items) My question is, how can I map the endpoint Get a Catalog Playlist's Relationship Di
1
0
1.3k
Apr ’22
Reply to Bug in .onmove for SwiftData models
[quote='756106021, Thomasmdelange, /thread/756106, /profile/Thomasmdelange'] .onMove { indexSet, offset in todo.items.move(fromOffsets: indexSet, toOffset: offset) } [/quote] The above code doesn't work because SwiftData doesn't retain the order of a relationship. To order the relationship shown in your code snippet, I'd probably consider the following: Use another query that provides the items of the specified todo for ItemListView. Add an order field for Item, and then use the field as a sort descriptor to order the result set for the Query in step #1. When the user changes the order in the item list, your app changes the order field of the relevant items. That change triggers a SwiftUI update, which then presents the items in the right order. Best, —— Ziqiao Chen  Worldwide Developer Relation.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’24
Observe a tree of Core Data relationships?
Background I'm working with Xcode 12.5.1 (12E507) and macOS 11.5.1. I am trying to show a tree of NSManagedObject instances in an NSOutlineView. Here's the general schema: The root of the tree I'm showing (object nil in the NSOutlineView) is always a Layer. Its list of rules can contain a mix of Rule objects and Section objects (thus the PolicyItem entity which Rules and Sections inherit from). Section objects can contain further Rule objects. Rules may contain a reference to another Layer, but generally don't. The canonical data is on a remote server accessed via an API. The server does not allow cycles (so a Layer contains a Section contains a Rule, but that Rule cannot reference the Layer it is under), so no need to account for that. I'm trying to handle rearranging rules. I have the drag-and-drop part working in the UI, and I am able to make the API call to rearrange the rule. The rule gets properly moved in the Core Data store, but on a background thread. Layer.rules can be an ordered relationship
4
0
1.9k
Jul ’21
SwiftUI and SwiftData @Query
Hey everyone, I’m relatively new to SwiftUI and iOS development, having started earlier this year, and I’m working on a Notes app using SwiftData. I’ve run into some issues when dealing with nested views. In my app, I’m using a SwiftData @Query in a parent view and then passing the model objects down the view tree. However, I’m frequently encountering errors such as “No container found” or similar. To work around this, I’ve tried having the child views perform their own SwiftData @Query, with the parent view passing a string identifier to the child views. This approach has helped somewhat, but I’m still not entirely sure how to properly manage UI updates. Additionally, I’ve noticed that turning on iCloud syncing seems to have made the problem worse. The errors have become more frequent, and it’s unclear to me how to handle these situations effectively. Could someone explain the best practices for handling SwiftData queries in nested SwiftUI views, especially with iCloud syn
Replies
1
Boosts
0
Views
1.5k
Activity
Aug ’24
How to use transformable in SwiftData?
Did anyone successfully used transformable in SwiftData to store UIColor or SwiftUI Color type? @Attribute(.transformable) var color: UIColor
Replies
6
Boosts
0
Views
4.9k
Activity
Jun ’23
Files & Folders not inheriting ACL permissions when opened, modified or created in shared SMB in Big Sur
Fishing for an answer... Trying to transfer (upgrade) a shared file server to a new Mac Mini M1 on Big Sur 1- File sharing is gone from Mac Os Server App So no more Make Inherited Entries Explicit. option! 2- I know I have to change the ACL Value of all those files different groups have access to different files.... 4- I have found this here https://discussions.apple.com/thread/250537136 chmod =a# 0 thegroup allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit BadShare Would love to chat with Strontium90 to help me understand And trying to apply it in Big Sur and it's not working. Here is what I have tried: Ex: I created a group name: test created a test folder named: testfld I used Dropbox to back all the files... chmod =a# 0 “test allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit /Users/server/Dropbox/BigBackUp/Tes
Replies
1
Boosts
0
Views
2.5k
Activity
Jul ’21
When will SwiftData support UInt64?
According to my experiments SwiftData does not work with model attributes of primitive type UInt64. More precisely, it crashes in the getter of a UInt64 attribute invoked on an object fetched from the data store. With Core Data persistent UInt64 attributes are not a problem. Does anyone know whether SwiftData will ever support UInt64?
Replies
2
Boosts
0
Views
437
Activity
Mar ’24
Access SwiftData in Widgets
How do I access the SwiftData ModelContainer of my app inside the widget extension? Following the guide to add a Widget Extension I’ve added the necessary target to my project and enabled App Groups. I’ve seen that the Backyard Birds example code offers an example how to build this, but it encapsulates the SwiftData handling in a separate app package. Therefore the example simply points to the app package. Though, in my case I don’t host my SwiftData in an external app package, but simply inside the regular app target. So, my question is how and at which point in code do I need to access the ModelContainer?
Replies
1
Boosts
0
Views
2.2k
Activity
Jun ’24
Reply to SwiftData on iOS 18 extreme memory use
Ziqiao, thanks for the fetchCount workaround. Unfortunately I've found another case. Simply iterating over a @Query with ForEach causes the same problem. No call to count. Your suggestion to make large items in externalStorage reference instead does help in this case too. But it points to a serious problem in SwiftData, where Query macros become useless in non-trivial apps. (I'm pretty sure that the problem does not happen when iterating or counting an array representing a one-to-many relationship. Hard to be sure because I can't get the app running well enough to exercise in iOS 18) I do hope that it's fixable, because this is not how SwiftData is supposed to work, and everything works fine on iOS 17.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’24
Does SwiftData require paging?
Hello. I'm going to create an app that supports purchase records. SwiftData was used to implement storage, backup, and restoration functions at once. One question is whether paging is necessary. When you receive data from a server, you usually implement paging to send and receive data efficiently. In the case of Realm, I know that it uses Lazy data, so I know that there is no need for paging. What about SwiftData? Can the number of data affect performance??
Replies
0
Boosts
0
Views
528
Activity
Jul ’24
SwiftData looses attribute when restarting app
I'm trying to archive some data in my SwiftUI app, using SwiftData. I implemented a Archive Model: import Foundation import SwiftData @Model class ArchiveData { let archiveName: String let archiveDate: Date @Relationship(.cascade) var items: [Item] init(archiveName: String, archiveDate: Date, items: [Item]) { self.archiveName = archiveName self.archiveDate = archiveDate self.items = items } } Then, I'm adding the data to the context: let newArchive = ArchiveData(archiveName: name, archiveDate: Date.now, items: items) context.insert(newArchive) I can then display the archived data in a separate view. But when I restart the app, the items array of ArchiveData is empty. I couldn't find out, where I made a mistake. Can anyone help me?
Replies
1
Boosts
0
Views
579
Activity
Jun ’23
Can't query for the existence of an optional to-one relationship?
Hi, say in my model I have members and each member optionally can have a relationship to a Club. So the relationship in the Member entity would be modelled like so: @Relationship(.nullify, inverse: Club.members) var club: Club? Now I would like to fetch al Members with no Club relationship. I would assume that this would work with a predicate like this: let noClubPred = #Predicate { member in member.club == nil } Unfortunately this gives me the following error when compiling: Generic parameter 'RHS' could not be inferred. Has anybody an idea how to phrase this predicate correctly, or is this a beta issue and it should actually work? Thank you! Cheers, Michael
Replies
2
Boosts
0
Views
1.3k
Activity
Jul ’23
Get a Catalog Playlist's Relationship Directly by Name
Hi there! I am trying to map the Apple Music API endpoints to MusicKit. For example, I am looking at the catalog playlist endpoints. To get a catalog playlist by its identifier, it is: let request = MusicCatalogResourceRequest(matching: .id, equalTo: pl.f4d106fed2bd41149aaacabb233eb5eb) let response = try await request.response() print(response.items) For multiple identifiers, it is: let request = MusicCatalogResourceRequest(matching: .id, memberOf: [pl.f4d106fed2bd41149aaacabb233eb5eb, pl.4b364b8b182f4115acbf6deb83bd5222]) let response = try await request.response() print(response.items) To get its relationship like more by curator and featured artists, I can set the properties: var request = MusicCatalogResourceRequest(matching: .id, equalTo: pl.f4d106fed2bd41149aaacabb233eb5eb) request.properties = [.featuredArtists, .moreByCurator, .tracks] let response = try await request.response() print(response.items) My question is, how can I map the endpoint Get a Catalog Playlist's Relationship Di
Replies
1
Boosts
0
Views
1.3k
Activity
Apr ’22
Is SwiftData created specifically for SwiftUI?
Many of Apple's tutorials on SwiftData are written alongside SwiftUI, including the sample code. Would it be a bad idea to use SwiftData separately? If I don't use SwiftUI, would it be wiser to choose a different database instead?
Replies
2
Boosts
0
Views
455
Activity
Apr ’24
Reply to Bug in .onmove for SwiftData models
[quote='756106021, Thomasmdelange, /thread/756106, /profile/Thomasmdelange'] .onMove { indexSet, offset in todo.items.move(fromOffsets: indexSet, toOffset: offset) } [/quote] The above code doesn't work because SwiftData doesn't retain the order of a relationship. To order the relationship shown in your code snippet, I'd probably consider the following: Use another query that provides the items of the specified todo for ItemListView. Add an order field for Item, and then use the field as a sort descriptor to order the result set for the Query in step #1. When the user changes the order in the item list, your app changes the order field of the relevant items. That change triggers a SwiftUI update, which then presents the items in the right order. Best, —— Ziqiao Chen  Worldwide Developer Relation.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’24
Observe a tree of Core Data relationships?
Background I'm working with Xcode 12.5.1 (12E507) and macOS 11.5.1. I am trying to show a tree of NSManagedObject instances in an NSOutlineView. Here's the general schema: The root of the tree I'm showing (object nil in the NSOutlineView) is always a Layer. Its list of rules can contain a mix of Rule objects and Section objects (thus the PolicyItem entity which Rules and Sections inherit from). Section objects can contain further Rule objects. Rules may contain a reference to another Layer, but generally don't. The canonical data is on a remote server accessed via an API. The server does not allow cycles (so a Layer contains a Section contains a Rule, but that Rule cannot reference the Layer it is under), so no need to account for that. I'm trying to handle rearranging rules. I have the drag-and-drop part working in the UI, and I am able to make the API call to rearrange the rule. The rule gets properly moved in the Core Data store, but on a background thread. Layer.rules can be an ordered relationship
Replies
4
Boosts
0
Views
1.9k
Activity
Jul ’21
SwiftData Vector Embeddings
Can vector embeddings be used in a SwiftData Model? If yes, are there resources available to learn more about it? or at least a guided step on how to make it work?
Replies
1
Boosts
0
Views
690
Activity
Oct ’24
SwiftData crashes the app
I get the following error when I try to add the modelContainer to the Window SwiftData/DataStoreCoreData.swift:119: Fatal error: Unable to determine Bundle Name
Replies
2
Boosts
0
Views
1.3k
Activity
Jun ’23