Search results for

“SwiftData inheritance relationship”

4,982 results found

Post

Replies

Boosts

Views

Activity

HealthKit SwiftData sync
Hello, I want to build an app that will allow the user to entry some health related records and be synced with the HealthKit. Any record that is in the HealthKit is stored locally on the device. I find it conceptually unsure if I should be storing the HealthKit records in the SwiftData to make the user records available across the iCloud synced devices. Should I read the HealthKit record, make a copy of it (including it's ID) on my app's data in SwiftData? How the syncing should be done the right way? thanks.
2
0
1.1k
Mar ’24
About relationship in CoreData-CloudKit Share
Now, when using NSPersistentCloudKitContainer.share(_ managedObjects: [NSManagedObject], to share: CKShare?), A deep traversal will be performed among the objects and any related objects will also be shared. For example, if there are 100 posts with the same tag, I shared one of them, and the remaining 99 will be shared at the same time. Is there any way to control whether the relationship should be shared?
0
0
1.2k
Dec ’21
Core Data - Accessing Relationship Objects vs. Fetchrequest
I'm wondering if there is a difference between accessing relationship objects directly vs. fetching them with a fetchrequest. What is more efficient and what is Core Data doing under the hood? Example: Let's pretend I have the entities 'Car' and 'Color' with many to many relationship. When I fetch a Car, it's relationship to its colors is a fault until I access it. What does happen when I access it with car.colors ? Is Core Data fetching these Color objects under the hood or have they been there already all the time since fetching the Car object? Does it make a performance difference when instead fetching the colors by a fetchrequest? -> fetchColors(for: car)
1
0
647
Jul ’22
Core Data transformable vs relationship
I'm working on an app that is using Core Data. I have a custom big number class that boils down to a double and an integer, plus math functions. I've been using transformable types to store these big numbers, but its forcing me to do a lot of ugly casts since the number class is used throughout the application. I figure I can either have my stored values be named differently (e.g. prefix with underscore) and have a computed variable to cast it to the correct type, or find some way to move the big number class to being an NSManagedObject. The issue with this is that the inverse relationships would be massive for the big number class, since multiple entities use the class in multiple properties already. Would it be recommended that I just keep using Transformable types and casts to handle this, or is there some standard way to handle a case like this in Core Data relationships?
0
0
347
Oct ’24
SwiftData and CloudKit
Recently I've been working on a demo project called iLibrary. The main goal was to learn more about CloudKit and SwiftData. After a while I noticed that there were some hangs/freezes when running the app in debug mode. I first tried this with Xcode 15.4 and iOS 17.5. Here the hang only appears at the beginning, but only for a few seconds. But when I exit debug mode, there are no more hangs. With Xcode 16 beta 4 and iOS 18 it looks completely different. In this case, the hangs and freezes are always present, whether in debug mode or not. And it's not just at the beginning, it's throughout the app. I'm aware that this is still a beta, but I still find this weird. And when I profile this I see that the main thread gets quite overloaded. Interestingly, my app doesn't have that many operations going on. So I guess something with the sync of SwiftData or my CloudKitManger where I fetch some records from the public database is not running fine. Lastly, I wanted to delete the iCloud app data. So I w
9
0
1.8k
Aug ’24
Reply to Task on MainActor does not run on the main thread, why?
The XCode documentation for Task says: ...the task created by Task.init(priority:operation:) inherits the priority and actor context of the caller, so the operation is treated more like an asynchronous extension to the synchronous operation. You wrote task don’t inherit their actor. If task does NOT inherit caller actor context, then everything is clear to me. Please, confirm.... (and please update the documentation accordingly)
Jul ’22
Why are to-many Core Data relationships represented as optionals?
As of Xcode 7b6, generating NSManagedObject subclasses for Swift in Xcode for an entity with a to-many relationship will generate a property of the optional type NSSet?. From what I can tell the underlying NSManagedObject data will always contain an empty (or not empty) set for that key. Is there a good reason to keep relationships optional and having to deal with unwrapping the values every time?
Topic: UI Frameworks SubTopic: AppKit Tags:
1
0
1.2k
Aug ’15
Are these @model classes correct for swiftdata with cloudkit?
I have used core data before via the model editor. This is the first time I'm using swift data and that too with CloudKit. Can you tell me if the following model classes are correct? I have an expense which can have only one sub category which in turn belongs to a single category. Here are my classes... // Expense.swift // Pocket Expense Diary // // Created by Neerav Kothari on 16/05/25. // import Foundation import SwiftData @Model class Expense { @Attribute var expenseDate: Date? = nil @Attribute var expenseAmount: Double? = nil @Attribute var expenseCategory: Category? = nil @Attribute var expenseSubCategory: SubCategory? = nil var date: Date { get { return expenseDate ?? Date() } set { expenseDate = newValue } } var amount: Double{ get { return expenseAmount ?? 0.0 } set { expenseAmount = newValue } } var category: Category{ get { return expenseCategory ?? Category.init(name: , icon: ) } set { expenseCategory = newValue } } var subCategory: SubCategory{ get { return expenseSubCategory ?? SubCatego
1
0
137
Jun ’25
Swiftdata Model crash
I am converting a large core data app to SwiftData and have hit a problem I can't fix, namely code generated by a Model crashing. Here is the model showing the failing expansion. Here is the model containing the inverse for the failing attribute: /Users/writingshedprod/Desktop/Screenshot 2024-05-08 at 20.21.51.png And here is the mass of core data output generated when the app launches. If anyone can make sense of this I'd be grateful. This is where the problem might lie. Debugger.txt
0
0
623
May ’24
SwiftData not syncing with iCloud
Hello everyone, I followed this (https://www.hackingwithswift.com/quick-start/swiftdata/how-to-sync-swiftdata-with-icloud) guide from Paul Hudson on how to sync swiftdata with iCloud. I tried it on my device directly and it worked exactly as I would expect. Now I tried the same version of the app on another device installed through TestFlight external tester group. It no longer works. When deleting the app, the alert reads Deleting this app will also delete its data, but any documents or data will be stored in iCloud will not be deleted so the app should have said something in iCloud. When looking in Settings -> Your Name -> iCloud -> Manage Account Storage, on the working device I can see around 300 KB saved in iCloud, on the other device my app is not listed. Both have a fast and working internet connection, almost fully charged, low data mode turned off, running 17.4.1, Background modes enabled, Mobile data enabled, more than enough unused iCloud storage and plenty of ti
2
0
3.2k
Mar ’24
HealthKit SwiftData sync
Hello, I want to build an app that will allow the user to entry some health related records and be synced with the HealthKit. Any record that is in the HealthKit is stored locally on the device. I find it conceptually unsure if I should be storing the HealthKit records in the SwiftData to make the user records available across the iCloud synced devices. Should I read the HealthKit record, make a copy of it (including it's ID) on my app's data in SwiftData? How the syncing should be done the right way? thanks.
Replies
2
Boosts
0
Views
1.1k
Activity
Mar ’24
About relationship in CoreData-CloudKit Share
Now, when using NSPersistentCloudKitContainer.share(_ managedObjects: [NSManagedObject], to share: CKShare?), A deep traversal will be performed among the objects and any related objects will also be shared. For example, if there are 100 posts with the same tag, I shared one of them, and the remaining 99 will be shared at the same time. Is there any way to control whether the relationship should be shared?
Replies
0
Boosts
0
Views
1.2k
Activity
Dec ’21
Core Data - Accessing Relationship Objects vs. Fetchrequest
I'm wondering if there is a difference between accessing relationship objects directly vs. fetching them with a fetchrequest. What is more efficient and what is Core Data doing under the hood? Example: Let's pretend I have the entities 'Car' and 'Color' with many to many relationship. When I fetch a Car, it's relationship to its colors is a fault until I access it. What does happen when I access it with car.colors ? Is Core Data fetching these Color objects under the hood or have they been there already all the time since fetching the Car object? Does it make a performance difference when instead fetching the colors by a fetchrequest? -> fetchColors(for: car)
Replies
1
Boosts
0
Views
647
Activity
Jul ’22
Reply to Test runner never began executing tests after launching
We fixed this issue by changing the inherit! property of the test target in our Podfile from :complete to :search_paths. We changed this: target 'App' do pod 'Pod', '~> 1.0' target 'AppTests' do inherit! :complete pod 'TestPod', '~>1.0' end end to this: target 'App' do pod 'Pod', '~> 1.0' target 'AppTests' do inherit! :search_paths pod 'TestPod', '~>1.0' end end
Replies
Boosts
Views
Activity
Mar ’22
Core Data transformable vs relationship
I'm working on an app that is using Core Data. I have a custom big number class that boils down to a double and an integer, plus math functions. I've been using transformable types to store these big numbers, but its forcing me to do a lot of ugly casts since the number class is used throughout the application. I figure I can either have my stored values be named differently (e.g. prefix with underscore) and have a computed variable to cast it to the correct type, or find some way to move the big number class to being an NSManagedObject. The issue with this is that the inverse relationships would be massive for the big number class, since multiple entities use the class in multiple properties already. Would it be recommended that I just keep using Transformable types and casts to handle this, or is there some standard way to handle a case like this in Core Data relationships?
Replies
0
Boosts
0
Views
347
Activity
Oct ’24
SwiftData conflict resolution?
If I change an object while offline, and then another device changes the same object, how is that change reconciled at sync time? Is there any mechanism to resolve conflicts in SwiftData?
Replies
0
Boosts
0
Views
688
Activity
Jul ’23
SwiftData and CloudKit
Recently I've been working on a demo project called iLibrary. The main goal was to learn more about CloudKit and SwiftData. After a while I noticed that there were some hangs/freezes when running the app in debug mode. I first tried this with Xcode 15.4 and iOS 17.5. Here the hang only appears at the beginning, but only for a few seconds. But when I exit debug mode, there are no more hangs. With Xcode 16 beta 4 and iOS 18 it looks completely different. In this case, the hangs and freezes are always present, whether in debug mode or not. And it's not just at the beginning, it's throughout the app. I'm aware that this is still a beta, but I still find this weird. And when I profile this I see that the main thread gets quite overloaded. Interestingly, my app doesn't have that many operations going on. So I guess something with the sync of SwiftData or my CloudKitManger where I fetch some records from the public database is not running fine. Lastly, I wanted to delete the iCloud app data. So I w
Replies
9
Boosts
0
Views
1.8k
Activity
Aug ’24
Reply to Xcode 3.2 swift shows error with the convenient initializer
What class do you try to inherit?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jan ’16
Reply to Task on MainActor does not run on the main thread, why?
The XCode documentation for Task says: ...the task created by Task.init(priority:operation:) inherits the priority and actor context of the caller, so the operation is treated more like an asynchronous extension to the synchronous operation. You wrote task don’t inherit their actor. If task does NOT inherit caller actor context, then everything is clear to me. Please, confirm.... (and please update the documentation accordingly)
Replies
Boosts
Views
Activity
Jul ’22
Why are to-many Core Data relationships represented as optionals?
As of Xcode 7b6, generating NSManagedObject subclasses for Swift in Xcode for an entity with a to-many relationship will generate a property of the optional type NSSet?. From what I can tell the underlying NSManagedObject data will always contain an empty (or not empty) set for that key. Is there a good reason to keep relationships optional and having to deal with unwrapping the values every time?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
1
Boosts
0
Views
1.2k
Activity
Aug ’15
Are these @model classes correct for swiftdata with cloudkit?
I have used core data before via the model editor. This is the first time I'm using swift data and that too with CloudKit. Can you tell me if the following model classes are correct? I have an expense which can have only one sub category which in turn belongs to a single category. Here are my classes... // Expense.swift // Pocket Expense Diary // // Created by Neerav Kothari on 16/05/25. // import Foundation import SwiftData @Model class Expense { @Attribute var expenseDate: Date? = nil @Attribute var expenseAmount: Double? = nil @Attribute var expenseCategory: Category? = nil @Attribute var expenseSubCategory: SubCategory? = nil var date: Date { get { return expenseDate ?? Date() } set { expenseDate = newValue } } var amount: Double{ get { return expenseAmount ?? 0.0 } set { expenseAmount = newValue } } var category: Category{ get { return expenseCategory ?? Category.init(name: , icon: ) } set { expenseCategory = newValue } } var subCategory: SubCategory{ get { return expenseSubCategory ?? SubCatego
Replies
1
Boosts
0
Views
137
Activity
Jun ’25
Swiftdata Model crash
I am converting a large core data app to SwiftData and have hit a problem I can't fix, namely code generated by a Model crashing. Here is the model showing the failing expansion. Here is the model containing the inverse for the failing attribute: /Users/writingshedprod/Desktop/Screenshot 2024-05-08 at 20.21.51.png And here is the mass of core data output generated when the app launches. If anyone can make sense of this I'd be grateful. This is where the problem might lie. Debugger.txt
Replies
0
Boosts
0
Views
623
Activity
May ’24
How to find relationship between logged-in users and processes?
Hello, Let's say I have several opened user sessions in parallel. Endpoint Security notify about executing a process (ES_EVENT_TYPE_NOTIFY_EXEC) and provide audit token. The goal is to find relationship between logged-in users and new process. Can I use audit user ID for this? Thank you in advance.
Replies
6
Boosts
0
Views
649
Activity
Nov ’24
Reply to App Crashes on performSegue(withIdentifier: id, sender: self)
I actually just found the issue when I was searching for the crash log for you. I was inheriting from UITableViewController when I needed to be inheriting from UIViewController. I made this mistake along the way when I was attempting to get it to segue to any controller. Thank you for the help!
Replies
Boosts
Views
Activity
May ’17
SwiftData not syncing with iCloud
Hello everyone, I followed this (https://www.hackingwithswift.com/quick-start/swiftdata/how-to-sync-swiftdata-with-icloud) guide from Paul Hudson on how to sync swiftdata with iCloud. I tried it on my device directly and it worked exactly as I would expect. Now I tried the same version of the app on another device installed through TestFlight external tester group. It no longer works. When deleting the app, the alert reads Deleting this app will also delete its data, but any documents or data will be stored in iCloud will not be deleted so the app should have said something in iCloud. When looking in Settings -> Your Name -> iCloud -> Manage Account Storage, on the working device I can see around 300 KB saved in iCloud, on the other device my app is not listed. Both have a fast and working internet connection, almost fully charged, low data mode turned off, running 17.4.1, Background modes enabled, Mobile data enabled, more than enough unused iCloud storage and plenty of ti
Replies
2
Boosts
0
Views
3.2k
Activity
Mar ’24