Search results for

“SwiftData inheritance relationship”

4,981 results found

Post

Replies

Boosts

Views

Activity

Reply to POP Implementations with multiple files
I think I would object to linking polymorphism to inheritance (which you kind of implied but didn't exactly do, so maybe you didn't mean that). Obj-C polymorphism is about the ability to send a message to an object without any particular requirement on the type of the object. The standard Print menu item, for example, relies on the polymorphism of the print: IBAction selector to enable printing for the circle, the star, the rectangle and the Word document. In fact, in Obj-C, polymorphism boils down to run-time dispatch. Swift tends to de-emphasize actual polymorphism by focusing on slightly polymorphic-ish features such as protocols and inheritance, which have significant compile-time limits when compared with Obj-C's free-for-all.However, what I really want to say is that in Swift, protocols and inheritance are not just alternative tools. There's a whole series of difficulties in using inheritance (fragile base classes, multiple inheritance, etc) that have led to
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’17
SwiftData update value
Hi I want to update item value after insert. Solution(False): I want to add isAutosaveEnabled prop to modelContainer, but modelContainer just have one parm. Solution2(False): There doesn't have API to update SwiftData, I just find insert, delete and save. I change the city_name and run try? modelContext.save(). But it replace after I reopen the app and maybe it doesn't work even before I close app. How can I update the city_name? /// --------- App --------- import SwiftUI import SwiftData @main struct MyApp: App { var container: ModelContainer init(){ let schema = Schema([ SD_City.self, ]) let modelConfiguration = ModelConfiguration(schema: schema) do { container = try ModelContainer(for: schema, configurations: [modelConfiguration]) let context = ModelContext(container) var city : SD_City city = SD_City(city_id: 1, city_name: city1) context.insert(city) city = SD_City(city_id: 2, city_name: city2) context.insert(city) } catch { fatalError(Could not create ModelContainer: ) } } var body: som
0
0
436
Jul ’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
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
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
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
How to completely reset SwiftData?
Is it possible to reset SwiftData to a state identical to that of a newly installed app? I have experienced some migration issues where, when I add a new model, I need to reinstall the entire application for the ModelContainer creation to work. Deleting all existing models does not seem to make any difference. A potential solution I currently have, which appears to work but feels quite hacky, is as follows: let _ = try! ModelContainer() modelContainer = try! ModelContainer(for: Student.self, ...) This seems to force out this error CoreData: error: Error: Persistent History (66) has to be truncated due to the following entities being removed: (...) which seems to reset SwiftData. Any other suggestions?
2
0
667
Nov ’24
Creating cross-store relationships
I am trying to use fetched property in store A to acess data in store B. In the core data documentation there is a reference to this capability :https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/HowManagedObjectsarerelated.html#//apple_ref/doc/uid/TP40001075-CH17-SW13I am a little confused though since the fetched property I created askes for a destination entity and only entities from store A are selectable.How can I make it so that I can set an entity in store B as a destination for a fetched property from store A?My problem is similar to this one: https://stackoverflow.com/questions/8209932/cross-store-weak-relationship-with-fetched-properties?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qaThanks in advance!
0
0
460
May ’18
Reply to POP Implementations with multiple files
I think I would object to linking polymorphism to inheritance (which you kind of implied but didn't exactly do, so maybe you didn't mean that). Obj-C polymorphism is about the ability to send a message to an object without any particular requirement on the type of the object. The standard Print menu item, for example, relies on the polymorphism of the print: IBAction selector to enable printing for the circle, the star, the rectangle and the Word document. In fact, in Obj-C, polymorphism boils down to run-time dispatch. Swift tends to de-emphasize actual polymorphism by focusing on slightly polymorphic-ish features such as protocols and inheritance, which have significant compile-time limits when compared with Obj-C's free-for-all.However, what I really want to say is that in Swift, protocols and inheritance are not just alternative tools. There's a whole series of difficulties in using inheritance (fragile base classes, multiple inheritance, etc) that have led to
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Mar ’17
SwiftData update value
Hi I want to update item value after insert. Solution(False): I want to add isAutosaveEnabled prop to modelContainer, but modelContainer just have one parm. Solution2(False): There doesn't have API to update SwiftData, I just find insert, delete and save. I change the city_name and run try? modelContext.save(). But it replace after I reopen the app and maybe it doesn't work even before I close app. How can I update the city_name? /// --------- App --------- import SwiftUI import SwiftData @main struct MyApp: App { var container: ModelContainer init(){ let schema = Schema([ SD_City.self, ]) let modelConfiguration = ModelConfiguration(schema: schema) do { container = try ModelContainer(for: schema, configurations: [modelConfiguration]) let context = ModelContext(container) var city : SD_City city = SD_City(city_id: 1, city_name: city1) context.insert(city) city = SD_City(city_id: 2, city_name: city2) context.insert(city) } catch { fatalError(Could not create ModelContainer: ) } } var body: som
Replies
0
Boosts
0
Views
436
Activity
Jul ’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
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
“More by Artist” Relationship View for Albums.
The supported Relationship Views for Albums in the API include appears-on, other-versions, related-albums, related-videos, but it doesn't support more-by-artist, this data is available when viewing the album in the Apple Music app and would be very useful if it was available in the Apple Music API and possibly MusicKit as well with new iOS update.
Replies
0
Boosts
0
Views
698
Activity
Jul ’22
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
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 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
How to completely reset SwiftData?
Is it possible to reset SwiftData to a state identical to that of a newly installed app? I have experienced some migration issues where, when I add a new model, I need to reinstall the entire application for the ModelContainer creation to work. Deleting all existing models does not seem to make any difference. A potential solution I currently have, which appears to work but feels quite hacky, is as follows: let _ = try! ModelContainer() modelContainer = try! ModelContainer(for: Student.self, ...) This seems to force out this error CoreData: error: Error: Persistent History (66) has to be truncated due to the following entities being removed: (...) which seems to reset SwiftData. Any other suggestions?
Replies
2
Boosts
0
Views
667
Activity
Nov ’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
Creating cross-store relationships
I am trying to use fetched property in store A to acess data in store B. In the core data documentation there is a reference to this capability :https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/HowManagedObjectsarerelated.html#//apple_ref/doc/uid/TP40001075-CH17-SW13I am a little confused though since the fetched property I created askes for a destination entity and only entities from store A are selectable.How can I make it so that I can set an entity in store B as a destination for a fetched property from store A?My problem is similar to this one: https://stackoverflow.com/questions/8209932/cross-store-weak-relationship-with-fetched-properties?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qaThanks in advance!
Replies
0
Boosts
0
Views
460
Activity
May ’18