Search results for

“SwiftData inheritance relationship”

4,981 results found

Post

Replies

Boosts

Views

Activity

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
How to count rows in SwiftData?
I'm currently writing an app that loads URLs from the HackerNews API. I have implemented Bookmarks by persisting any bookmarked data to SwiftData. I am currently trying to implemented viewed links — i.e. if you click a link, it gets marked as viewed — I was able to do so by persisting the link ID to SwiftData and in each link view, it queries for itself against the existing viewed links, like so: static func viewedPredicate(_ id: Int) -> Predicate { return #Predicate { $0.id == id } } var viewed: [Viewed] { return (try? modelContext.fetch( FetchDescriptor( predicate: ItemView.viewedPredicate(id) ))) ?? [] } But now, I want to provide stats to the user, so I need to count how many viewed links exist. I don't want to return ALL objects from SwiftData, I want a simple Int that tells me how many there are. To do so, I implemented it as follows: private var viewedCount: Int { return (try? modelContext.fetchCount(FetchDescriptor())) ?? 0 } But when I delete the stats, the number does n
1
0
1.3k
Oct ’23
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
SwiftData Remote Database Updates
I just saw the new SwiftData updates, including the DataStore API. I’m wondering if, in the case of a shared remote datastore, it is possible to enable updates to the model context from the datastore without the model context explicitly requesting them (e.g., through database listeners). If I’m not mistaken, when you use CloudKit with SwiftData, this happens, right?
1
0
559
Jun ’24
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
SwiftData with inMemory storage promptly crashes with nw_socket_handle_socket_event
When my code tries to access a SwiftData model's relationship, my app promptly crashes with nw_socket_handle_socket_event [C1.1.1:2] Socket SO_ERROR 61 and no useful information. How do I go about debugging this? I'm creating my modelContainer as inMemory, so I don't think this should be touching any SQLite DB: @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } .modelContainer( for: SchemaV1.models, inMemory: true, isAutosaveEnabled: false, isUndoEnabled: false) } }
1
0
659
Oct ’23
Tabs with SwiftData
Hello folks, absolute newbie here. I'm following a tutorial that I'm trying to adjust to my own needs. In the tutorial the app is sat up in a way that you can add a new entry to a note taking app by tapping on a button which brings in an edit view. What I'm trying to do is to bring in the edit view by adding it as a tab on the bottom instead. Here's my ContentView: import SwiftData import SwiftUI struct ContentView: View { let example = Entry(content: Example Entry) var body: some View { TabView { LifeEventsView() .tabItem { Label(Life events, systemImage: house) } EditEntryView(entry: example) .tabItem { Label(Add new event, systemImage: plus) } MattersView() .tabItem { Label(What matters, systemImage: house) } } } } #Preview { ContentView() } And here's the EditEntryView: import SwiftData struct EditEntryView: View { @Bindable var entry: Entry var body: some View { Form { TextField(Entry, text: $entry.content, axis: .vertical) } .navigationTitle(Edit entry) .navigationBarTitleDisplayMode(.
0
0
458
Jul ’24
Help to understand SwiftData
Hello! I apologize in advance if I chose the wrong topic for my question, this is my first time on this forum. I am a novice developer and I am creating an application. I use Swift + SwiftUI, but I ran into such a problem that I have nowhere to store my data and I do not know how to store it correctly. I know that there is a SwiftData framework that is used to work with data, but I don't understand the documentation. Please be understanding. How do I start learning SwiftData? What topics should be studied? What is the order of studying topics? Thank you all in advance!
1
0
474
Aug ’24
Reply to Importing Data into SwiftData in the Background Using ModelActor and @Query
Yes, it seems something was fixed (using Beta 6 and Xcode 16 b5). In my case I could get rid of the previous workaround with Notification Center and I can see the changes reflecting in the views. However there are definitely new problems with saving models - in some cases it appears a model's @Relationship is not saved. Will try to recreate this in a test project. In the meantime, @DTS Engineer - any comments on the new changes? PS. it is really quite frustrating that there is no mention of SwiftData issues in any of the Release Notes although changes are evidently being made
Aug ’24
Multiple relationship variables of the the same type
Want to know if it's possible to have multiple variables of the same type? This code works but when the app loads the data again on relaunch, both variables have both the new cards and discarded cards. @Model class Player { let id = UUID() let name: String @Relationship(deleteRule: .cascade, inverse: Card.player) var cards: [Card] = [] @Relationship(deleteRule: .cascade, inverse: Card.player) var discardedCards: [Card] = [] init(name: String, cards: [Card]) { self.name = name self.cards = cards } } @Model class Card { let id = UUID() let name: String var player: Player? init(name: String) { self.name = name } }
0
0
315
Jul ’24
SwiftData crash: PersistentModel.keyPathToString(keypath:)
I'm distributing an iOS (17.4+) and visionOS (1.2+) app via TestFlight that's using SwiftData. The most common crash by far is from SwiftData when deleting models from a context using a predicate (first snippet below), but so far I've been unable to reproduce it myself locally (second snippet below). I'm using SwiftData outside of SwiftUI views, via my own wrapper, and converting between my app models and SwiftData models. Does anyone have any ideas how I could potentially narrow this issue down (or reproduce), or know of any similar issues? Thanks! — Seb do { try context.transaction { context in let predicate = #Predicate { $0.id == id } do { try context.delete(model: PersistedFeed.self, where: predicate) } catch { // .. Omitted for brevity } } } catch { // .. Omitted for brevity } Crash: Thread 0 Crashed: 0 libswiftCore.dylib 0x000000018dd558c0 _assertionFailure(_:_:file:line:flags:) + 264 (AssertCommon.swift:144) 1 SwiftData 0x000000022f7f323c static PersistentM
1
0
753
Jun ’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
Replies
1
Boosts
0
Views
2.5k
Activity
Jul ’21
How to count rows in SwiftData?
I'm currently writing an app that loads URLs from the HackerNews API. I have implemented Bookmarks by persisting any bookmarked data to SwiftData. I am currently trying to implemented viewed links — i.e. if you click a link, it gets marked as viewed — I was able to do so by persisting the link ID to SwiftData and in each link view, it queries for itself against the existing viewed links, like so: static func viewedPredicate(_ id: Int) -> Predicate { return #Predicate { $0.id == id } } var viewed: [Viewed] { return (try? modelContext.fetch( FetchDescriptor( predicate: ItemView.viewedPredicate(id) ))) ?? [] } But now, I want to provide stats to the user, so I need to count how many viewed links exist. I don't want to return ALL objects from SwiftData, I want a simple Int that tells me how many there are. To do so, I implemented it as follows: private var viewedCount: Int { return (try? modelContext.fetchCount(FetchDescriptor())) ?? 0 } But when I delete the stats, the number does n
Replies
1
Boosts
0
Views
1.3k
Activity
Oct ’23
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
SwiftData Remote Database Updates
I just saw the new SwiftData updates, including the DataStore API. I’m wondering if, in the case of a shared remote datastore, it is possible to enable updates to the model context from the datastore without the model context explicitly requesting them (e.g., through database listeners). If I’m not mistaken, when you use CloudKit with SwiftData, this happens, right?
Replies
1
Boosts
0
Views
559
Activity
Jun ’24
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
SwiftData and command line
Is it possible to use SwiftData in a CLI tool, or is it only designed to work with SwiftUI?
Replies
13
Boosts
0
Views
3.3k
Activity
Jul ’23
SwiftData with inMemory storage promptly crashes with nw_socket_handle_socket_event
When my code tries to access a SwiftData model's relationship, my app promptly crashes with nw_socket_handle_socket_event [C1.1.1:2] Socket SO_ERROR 61 and no useful information. How do I go about debugging this? I'm creating my modelContainer as inMemory, so I don't think this should be touching any SQLite DB: @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } .modelContainer( for: SchemaV1.models, inMemory: true, isAutosaveEnabled: false, isUndoEnabled: false) } }
Replies
1
Boosts
0
Views
659
Activity
Oct ’23
Tabs with SwiftData
Hello folks, absolute newbie here. I'm following a tutorial that I'm trying to adjust to my own needs. In the tutorial the app is sat up in a way that you can add a new entry to a note taking app by tapping on a button which brings in an edit view. What I'm trying to do is to bring in the edit view by adding it as a tab on the bottom instead. Here's my ContentView: import SwiftData import SwiftUI struct ContentView: View { let example = Entry(content: Example Entry) var body: some View { TabView { LifeEventsView() .tabItem { Label(Life events, systemImage: house) } EditEntryView(entry: example) .tabItem { Label(Add new event, systemImage: plus) } MattersView() .tabItem { Label(What matters, systemImage: house) } } } } #Preview { ContentView() } And here's the EditEntryView: import SwiftData struct EditEntryView: View { @Bindable var entry: Entry var body: some View { Form { TextField(Entry, text: $entry.content, axis: .vertical) } .navigationTitle(Edit entry) .navigationBarTitleDisplayMode(.
Replies
0
Boosts
0
Views
458
Activity
Jul ’24
Alternative ideas for NSBatchInsertRequest to set relationships
Hi everybody, I know that NSBatchInsertRequest doesn't let you to set the relationship between Entities. And if you try to set Xcode gets angry and says you that the problem is that record is in other context and you can't modify it. So, Anyone knows any solution, alternative to solve this problem? thank you
Replies
0
Boosts
0
Views
889
Activity
Jun ’21
Help to understand SwiftData
Hello! I apologize in advance if I chose the wrong topic for my question, this is my first time on this forum. I am a novice developer and I am creating an application. I use Swift + SwiftUI, but I ran into such a problem that I have nowhere to store my data and I do not know how to store it correctly. I know that there is a SwiftData framework that is used to work with data, but I don't understand the documentation. Please be understanding. How do I start learning SwiftData? What topics should be studied? What is the order of studying topics? Thank you all in advance!
Replies
1
Boosts
0
Views
474
Activity
Aug ’24
Reply to Importing Data into SwiftData in the Background Using ModelActor and @Query
Yes, it seems something was fixed (using Beta 6 and Xcode 16 b5). In my case I could get rid of the previous workaround with Notification Center and I can see the changes reflecting in the views. However there are definitely new problems with saving models - in some cases it appears a model's @Relationship is not saved. Will try to recreate this in a test project. In the meantime, @DTS Engineer - any comments on the new changes? PS. it is really quite frustrating that there is no mention of SwiftData issues in any of the Release Notes although changes are evidently being made
Replies
Boosts
Views
Activity
Aug ’24
Multiple relationship variables of the the same type
Want to know if it's possible to have multiple variables of the same type? This code works but when the app loads the data again on relaunch, both variables have both the new cards and discarded cards. @Model class Player { let id = UUID() let name: String @Relationship(deleteRule: .cascade, inverse: Card.player) var cards: [Card] = [] @Relationship(deleteRule: .cascade, inverse: Card.player) var discardedCards: [Card] = [] init(name: String, cards: [Card]) { self.name = name self.cards = cards } } @Model class Card { let id = UUID() let name: String var player: Player? init(name: String) { self.name = name } }
Replies
0
Boosts
0
Views
315
Activity
Jul ’24
SwiftData crash: PersistentModel.keyPathToString(keypath:)
I'm distributing an iOS (17.4+) and visionOS (1.2+) app via TestFlight that's using SwiftData. The most common crash by far is from SwiftData when deleting models from a context using a predicate (first snippet below), but so far I've been unable to reproduce it myself locally (second snippet below). I'm using SwiftData outside of SwiftUI views, via my own wrapper, and converting between my app models and SwiftData models. Does anyone have any ideas how I could potentially narrow this issue down (or reproduce), or know of any similar issues? Thanks! — Seb do { try context.transaction { context in let predicate = #Predicate { $0.id == id } do { try context.delete(model: PersistedFeed.self, where: predicate) } catch { // .. Omitted for brevity } } } catch { // .. Omitted for brevity } Crash: Thread 0 Crashed: 0 libswiftCore.dylib 0x000000018dd558c0 _assertionFailure(_:_:file:line:flags:) + 264 (AssertCommon.swift:144) 1 SwiftData 0x000000022f7f323c static PersistentM
Replies
1
Boosts
0
Views
753
Activity
Jun ’24