Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Xcode 9 beta 5: Failed to push inherited simulated metrics to all scenes
Opening the storyboard of my current project in Xcode 9 beta 5 results in a crash:Process: Xcode [2478] Path: /Applications/Xcode-beta.app/Contents/MacOS/Xcode Identifier: com.apple.dt.Xcode Version: 9.0 (13226.5) Build Info: IDEFrameworks-13226005000000000~14 Code Type: X86-64 (Native) Parent Process: ??? [1] Responsible: Xcode [2478] User ID: 501 Date/Time: 2017-08-08 09:31:41.091 +0200 OS Version: Mac OS X 10.12.6 (16G29) Report Version: 12 Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Application Specific Information: ProductBuildVersion: 9M202q ASSERTION FAILURE in /Library/Caches/com.apple.xbs/Sources/IDEInterfaceBuilder/IDEInterfaceBuilder-13178.6/InterfaceBuilderKit/Document/StoryboardDocument/Metrics/IBStoryboardMetricsInferrer.m:128 Details: Failed to push inherited simulated metrics to all scenes. Object: <IBStoryboardMetricsInferrer: 0x7f86ce1cd820>
1
0
1k
Aug ’17
Relationships between structs and detecting changes
I'm currently working on an app which has a number of different data objects with relationships between them. For example, there is a Building struct: struct Building { let id: UUID var name: String } There is also an Address struct, which has a Building property: struct Address: { let id: UUID var addressText: String var building: Building } When I change the name of the Building I would like it to update for all the corresponding Address objects. Because structs are value types, this doesn't happen at present. I could fix this by changing struct to class, but because I'm working with SwiftUI that's not desirable. I could fix this by updating the Address to store the id of the Building instead but having to look up the name of the corresponding building each time I want it feels messy to me. Is there some other approach I'm missing? Or a recommended best practice way of handling relationships between structs?
3
0
629
Jun ’22
Relationship is initialized with boolean value
I have an iOS app written in Swift 2, compiled using Xcode 7.1.1, using Core Data.One of the entities in my model seems to be initialized with the wrong type of values, and I am out of ideas on how to diagnose and fix the problem.Even though my app is using a multi-context Core Data stack, I am able to reproduce the problem with a vanilla Core Data stack (code generated by the Xcode template), using this code in my main view controller's viewDidAppear method:let moc = self.managedObjectContext // Vanilla context from Xcode's Core Data template let e = NSEntityDescription.insertNewObjectForEntityForName(TaskDefinition, inManagedObjectContext: moc) for (name, _) in e.entity.relationshipsByName { print(name) print(e.valueForKey(name)) }Here's the console output:owner nil sharedSlave Optional(0) schoolYearConfiguration nil attachments 2015-12-07 13:35:04.869 Studyo Beta[43113:15618215] -[__NSCFBoolean objectID]: unrecognized selector sent to instance 0x104b51248There are 2 things to note from this log:Line 4: The
4
0
929
Dec ’15
SwiftUI CoreData relationship binding Bug
I developing simple app to calculate personal money income and consumption. I use CORE DATA to save my model. The models consists of this CDCatalogWallet var name: String var ref: String CDCatalogStateIncome var name: String var ref: String CDDocumentIncome var ref: String var wallet: CDCatalogWallet (relationship has one) var states_: CDDocumentIncomeState (relationship has many) CDDocumentIncomeState var cdCatalogStateIncome: CDCatalogStateIncome (relationship has one) var document: CDDocumentIncome (relationship has one) CDDocumentIncome hasMany -> CDDocumentIncomeState hasOne -> CDCatalogStateIncome The bug shows when we pushing CDDocumentIncomeState view The model is simple. The CDDocumentIncome has relationship property cdCatalogStateIncome (relationship many). We open view with CDDocumentIncome and want to add new cdCatalogStateIncome to CDDocumentIncome Then we open view with new cdCatalogStateIncome. On this screen cdCatalogStateIncome has a
1
0
641
Feb ’24
@SectionedFetchRequest using relationship as sectionIdentifier
As the title says I'm trying to use a to-one relationship as a sectionIdentifier in a @SectionedFetchRequest. The compiler is happy but there's a runtime crash: Could not cast value of type '_NSCoreDataTaggedObjectID' (0x146c0f750) to 'MyApp.ServiceCategory' (0x104c4b3a0). The fetch request: @SectionedFetchRequest( sectionIdentifier: Service.serviceCategory, sortDescriptors: [ SortDescriptor(Service.active, order: .reverse), SortDescriptor(Service.displayText) ], predicate: NSPredicate(format: %K = %d, #keyPath(Service.active), true), animation: .default ) var sectionedServices: SectionedFetchResults ... and the breaking runtime code: ForEach(sectionedServices /* here */) { section in Section(header: Text(section.id?.displayText ?? )) { ForEach(section) { svc in Text(svc.displayText ?? ) } } } The request works if I switch out the sectionIdentifier for the active property (which is a Bool property rather than a relationship). It also works if I switch it out for displayText which is an optio
4
0
2.3k
Jun ’21
SwiftData
As soon as I invoke a call for import SwiftData I am getting this error Linker command failed with exit code 1 (use -v to see invocation) Before deleting, I went to the Library Directory and manually Deleted the directory of Developer. And then I proceeded to deleted Xcode beta 3 and downloaded a fresh beta 2 and I still have the same error. I even deleted beta 2 and reinstall beta 1 and still the same error. Can someone give me any direction please Robert Update: I erased the hard drive and installed a Fresh MacOS 13.4.1 with a Fresh never ran Xcode beta 3 and right away as soon as I ran it the first time, I am having the same problem. WHAT IS GOING ON???
0
0
443
Jul ’23
Reply to SwiftData - Context missing for optional
This error indicates that your model object doesn't have a valid model context, which can happen when you hold a SwiftData model object in a SwiftUI view and continue to access the object (as the view is updated) after it was deleted. In my case it was exactly as @DTS Engineer pointed out. One of my parent views State properties was holding a model object where the relationship property was a deleted model object. That relationship was still accessed in the parent view and lead to the crash. Explicitly setting those states to nil helped resolving the issue. It took some time to identify where the issue happened exactly. What helped was the backtrace of the main thread inside the Debug Navigator. Hope that helps.
Sep ’24
Unit testing SwiftData
Problem Trying out SwiftData, I attempted to write unit tests for some models I was writing, but got a crash when testing appending to a collection. Context Here's a sample reminiscent of the set up I have: // Foo.swift import SwiftData @Model final class Foo { @Relationship(.cascade) private(set) var barCollection: [Bar] = [Bar]() ... func append(bar: Bar) { defer { // some logic here } barCollection.append(bar) } } // Bar.swift import SwiftData @Model final class Bar { var value: Int init(value: Int) { self.value = value } } In my test, I'm attempting to append to the Bar array, and ensure that my append(bar:) method is doing it's job: // FooTests.swift @testable import FooApp import XCTest final class FooTests: XCTestCase { func testAppendBar() { let foo = Foo(bar: []) foo.append(bar: Bar(value: 0)) XCTAssertFalse(foo.barCollection.isEmpty) // Assertions for logic enclosed in `defer` . . . } } However, my test crashes on the assertion with EXC_BREAKPOINT, claiming issues
1
0
2k
Jul ’23
Uniqueness with to-one mandatory inverse relationship
Why entity cannot have uniqueness constraints with to-one mandatory inverse relationship?Having two entities:- Personproperty: namerelationship: department (to-one, non-optional)- Departmentproperty: title (unique constraint)relationship: person (to-many, optional)Model won't compile in iOS 9, XCode 7.0.1 with misconfigured entity error:Misconfigured Entity: Entity Department cannot have uniqueness constraints and to-one mandatory inverse relationship Person.department
8
0
3.8k
Sep ’15
SwiftData Component
Hello, I'm a little new to Swift and very new to SwiftData. I'm making a flashcard app in which the decks of flashcards are displayed in a view. I've created a reusable component for the decks in which I want to use SwiftData to store the Title date of creation and eventually number of cards. So far I'm just trying to get the title. Here is the component: Deck Component import SwiftUI import SwiftData struct DeckRow: View { @State private var isPressed = false @State private var isToggled = false @Environment(.modelContext) var modelContext @Query var decks: [Deck] var body: some View { ZStack { RoundedRectangle(cornerRadius: 20) .frame(height: 99) .padding(.horizontal) .foregroundStyle(Color.primaryC) .offset(y: 8) HStack(alignment: .top) { VStack(alignment: .leading, spacing: 20) { HStack { Text(decks.name) .font(.title2) .bold() Text(2w) .font(.subheadline) .fontWeight(.light) } HStack { Image(systemName: square.3.layers.3d.top.filled) Text(20 Cards) } } Spacer() Button { } label
1
0
800
Oct ’23
SwiftData crash on fetch
I have a strange crash which I have problems understanding. It only happens on a few devices, after a ModelContainer migration, and it doesn't seem to crash on the migration itself. The fetch is done in onAppear, and shouldn't necessarily result in a crash, as it is an optional try: let request = FetchDescriptor() let data = try? modelContext.fetch(request) if let data, !data.isEmpty { rifle = data.first(where: { $0.uuid.uuidString == settings.selectedRifleId }) ?? data.first! } When I get logs from users, there seems to be an error in encoding? Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000018e8bfd78 Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [71687] Triggered by Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libswiftCore.dylib 0x18e8bfd78 _assertionFailure(_:_:file:line:flags:) + 264 1 SwiftData 0x24e18b480 0x24e14c000 + 259200 2 SwiftData 0x24e193968 0x24e14c000 + 293224 3 SwiftData
9
0
862
Oct ’24
Query relationship hierarchy
I have a fundamental question for Queries in CloudKit.I have a relationship structure set with references where Courses->Holes->Locations. Basically a course owns 18 holes, which each own 4 locations...Is there a way to query to find all locations beneath a given Course without querying by hole? I am trying to reduce the number of queries I have to do to CloudKit to get the information I need.Today I query to get the record for a Course, then one query for all the holes belonging to that course, then I have 18 queries for locations by hole...If I could query all locations in a course, I could reduce my queries from 20 total to 3 total. I know this is possible for a similar structure in coreData. Can't figure it out for Cloudkit.
0
0
131
Apr ’16
Xcode 9 beta 5: Failed to push inherited simulated metrics to all scenes
Opening the storyboard of my current project in Xcode 9 beta 5 results in a crash:Process: Xcode [2478] Path: /Applications/Xcode-beta.app/Contents/MacOS/Xcode Identifier: com.apple.dt.Xcode Version: 9.0 (13226.5) Build Info: IDEFrameworks-13226005000000000~14 Code Type: X86-64 (Native) Parent Process: ??? [1] Responsible: Xcode [2478] User ID: 501 Date/Time: 2017-08-08 09:31:41.091 +0200 OS Version: Mac OS X 10.12.6 (16G29) Report Version: 12 Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Application Specific Information: ProductBuildVersion: 9M202q ASSERTION FAILURE in /Library/Caches/com.apple.xbs/Sources/IDEInterfaceBuilder/IDEInterfaceBuilder-13178.6/InterfaceBuilderKit/Document/StoryboardDocument/Metrics/IBStoryboardMetricsInferrer.m:128 Details: Failed to push inherited simulated metrics to all scenes. Object: <IBStoryboardMetricsInferrer: 0x7f86ce1cd820>
Replies
1
Boosts
0
Views
1k
Activity
Aug ’17
Relationships between structs and detecting changes
I'm currently working on an app which has a number of different data objects with relationships between them. For example, there is a Building struct: struct Building { let id: UUID var name: String } There is also an Address struct, which has a Building property: struct Address: { let id: UUID var addressText: String var building: Building } When I change the name of the Building I would like it to update for all the corresponding Address objects. Because structs are value types, this doesn't happen at present. I could fix this by changing struct to class, but because I'm working with SwiftUI that's not desirable. I could fix this by updating the Address to store the id of the Building instead but having to look up the name of the corresponding building each time I want it feels messy to me. Is there some other approach I'm missing? Or a recommended best practice way of handling relationships between structs?
Replies
3
Boosts
0
Views
629
Activity
Jun ’22
Relationship is initialized with boolean value
I have an iOS app written in Swift 2, compiled using Xcode 7.1.1, using Core Data.One of the entities in my model seems to be initialized with the wrong type of values, and I am out of ideas on how to diagnose and fix the problem.Even though my app is using a multi-context Core Data stack, I am able to reproduce the problem with a vanilla Core Data stack (code generated by the Xcode template), using this code in my main view controller's viewDidAppear method:let moc = self.managedObjectContext // Vanilla context from Xcode's Core Data template let e = NSEntityDescription.insertNewObjectForEntityForName(TaskDefinition, inManagedObjectContext: moc) for (name, _) in e.entity.relationshipsByName { print(name) print(e.valueForKey(name)) }Here's the console output:owner nil sharedSlave Optional(0) schoolYearConfiguration nil attachments 2015-12-07 13:35:04.869 Studyo Beta[43113:15618215] -[__NSCFBoolean objectID]: unrecognized selector sent to instance 0x104b51248There are 2 things to note from this log:Line 4: The
Replies
4
Boosts
0
Views
929
Activity
Dec ’15
SwiftUI CoreData relationship binding Bug
I developing simple app to calculate personal money income and consumption. I use CORE DATA to save my model. The models consists of this CDCatalogWallet var name: String var ref: String CDCatalogStateIncome var name: String var ref: String CDDocumentIncome var ref: String var wallet: CDCatalogWallet (relationship has one) var states_: CDDocumentIncomeState (relationship has many) CDDocumentIncomeState var cdCatalogStateIncome: CDCatalogStateIncome (relationship has one) var document: CDDocumentIncome (relationship has one) CDDocumentIncome hasMany -> CDDocumentIncomeState hasOne -> CDCatalogStateIncome The bug shows when we pushing CDDocumentIncomeState view The model is simple. The CDDocumentIncome has relationship property cdCatalogStateIncome (relationship many). We open view with CDDocumentIncome and want to add new cdCatalogStateIncome to CDDocumentIncome Then we open view with new cdCatalogStateIncome. On this screen cdCatalogStateIncome has a
Replies
1
Boosts
0
Views
641
Activity
Feb ’24
@SectionedFetchRequest using relationship as sectionIdentifier
As the title says I'm trying to use a to-one relationship as a sectionIdentifier in a @SectionedFetchRequest. The compiler is happy but there's a runtime crash: Could not cast value of type '_NSCoreDataTaggedObjectID' (0x146c0f750) to 'MyApp.ServiceCategory' (0x104c4b3a0). The fetch request: @SectionedFetchRequest( sectionIdentifier: Service.serviceCategory, sortDescriptors: [ SortDescriptor(Service.active, order: .reverse), SortDescriptor(Service.displayText) ], predicate: NSPredicate(format: %K = %d, #keyPath(Service.active), true), animation: .default ) var sectionedServices: SectionedFetchResults ... and the breaking runtime code: ForEach(sectionedServices /* here */) { section in Section(header: Text(section.id?.displayText ?? )) { ForEach(section) { svc in Text(svc.displayText ?? ) } } } The request works if I switch out the sectionIdentifier for the active property (which is a Bool property rather than a relationship). It also works if I switch it out for displayText which is an optio
Replies
4
Boosts
0
Views
2.3k
Activity
Jun ’21
SwiftData
As soon as I invoke a call for import SwiftData I am getting this error Linker command failed with exit code 1 (use -v to see invocation) Before deleting, I went to the Library Directory and manually Deleted the directory of Developer. And then I proceeded to deleted Xcode beta 3 and downloaded a fresh beta 2 and I still have the same error. I even deleted beta 2 and reinstall beta 1 and still the same error. Can someone give me any direction please Robert Update: I erased the hard drive and installed a Fresh MacOS 13.4.1 with a Fresh never ran Xcode beta 3 and right away as soon as I ran it the first time, I am having the same problem. WHAT IS GOING ON???
Replies
0
Boosts
0
Views
443
Activity
Jul ’23
Reply to SwiftData - Context missing for optional
This error indicates that your model object doesn't have a valid model context, which can happen when you hold a SwiftData model object in a SwiftUI view and continue to access the object (as the view is updated) after it was deleted. In my case it was exactly as @DTS Engineer pointed out. One of my parent views State properties was holding a model object where the relationship property was a deleted model object. That relationship was still accessed in the parent view and lead to the crash. Explicitly setting those states to nil helped resolving the issue. It took some time to identify where the issue happened exactly. What helped was the backtrace of the main thread inside the Debug Navigator. Hope that helps.
Replies
Boosts
Views
Activity
Sep ’24
Unit testing SwiftData
Problem Trying out SwiftData, I attempted to write unit tests for some models I was writing, but got a crash when testing appending to a collection. Context Here's a sample reminiscent of the set up I have: // Foo.swift import SwiftData @Model final class Foo { @Relationship(.cascade) private(set) var barCollection: [Bar] = [Bar]() ... func append(bar: Bar) { defer { // some logic here } barCollection.append(bar) } } // Bar.swift import SwiftData @Model final class Bar { var value: Int init(value: Int) { self.value = value } } In my test, I'm attempting to append to the Bar array, and ensure that my append(bar:) method is doing it's job: // FooTests.swift @testable import FooApp import XCTest final class FooTests: XCTestCase { func testAppendBar() { let foo = Foo(bar: []) foo.append(bar: Bar(value: 0)) XCTAssertFalse(foo.barCollection.isEmpty) // Assertions for logic enclosed in `defer` . . . } } However, my test crashes on the assertion with EXC_BREAKPOINT, claiming issues
Replies
1
Boosts
0
Views
2k
Activity
Jul ’23
Uniqueness with to-one mandatory inverse relationship
Why entity cannot have uniqueness constraints with to-one mandatory inverse relationship?Having two entities:- Personproperty: namerelationship: department (to-one, non-optional)- Departmentproperty: title (unique constraint)relationship: person (to-many, optional)Model won't compile in iOS 9, XCode 7.0.1 with misconfigured entity error:Misconfigured Entity: Entity Department cannot have uniqueness constraints and to-one mandatory inverse relationship Person.department
Replies
8
Boosts
0
Views
3.8k
Activity
Sep ’15
SwiftData Component
Hello, I'm a little new to Swift and very new to SwiftData. I'm making a flashcard app in which the decks of flashcards are displayed in a view. I've created a reusable component for the decks in which I want to use SwiftData to store the Title date of creation and eventually number of cards. So far I'm just trying to get the title. Here is the component: Deck Component import SwiftUI import SwiftData struct DeckRow: View { @State private var isPressed = false @State private var isToggled = false @Environment(.modelContext) var modelContext @Query var decks: [Deck] var body: some View { ZStack { RoundedRectangle(cornerRadius: 20) .frame(height: 99) .padding(.horizontal) .foregroundStyle(Color.primaryC) .offset(y: 8) HStack(alignment: .top) { VStack(alignment: .leading, spacing: 20) { HStack { Text(decks.name) .font(.title2) .bold() Text(2w) .font(.subheadline) .fontWeight(.light) } HStack { Image(systemName: square.3.layers.3d.top.filled) Text(20 Cards) } } Spacer() Button { } label
Replies
1
Boosts
0
Views
800
Activity
Oct ’23
Using SwiftData in background?
How does SwiftData work with background operations? CoreData had background context that could be used to avoid UI hang for heavy operations. Is there an equivalent in SwiftData, and if so, do I have to merge changes or does it save directly to persistent store?
Replies
5
Boosts
0
Views
5.6k
Activity
Jun ’23
SwiftData crash on fetch
I have a strange crash which I have problems understanding. It only happens on a few devices, after a ModelContainer migration, and it doesn't seem to crash on the migration itself. The fetch is done in onAppear, and shouldn't necessarily result in a crash, as it is an optional try: let request = FetchDescriptor() let data = try? modelContext.fetch(request) if let data, !data.isEmpty { rifle = data.first(where: { $0.uuid.uuidString == settings.selectedRifleId }) ?? data.first! } When I get logs from users, there seems to be an error in encoding? Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000018e8bfd78 Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [71687] Triggered by Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libswiftCore.dylib 0x18e8bfd78 _assertionFailure(_:_:file:line:flags:) + 264 1 SwiftData 0x24e18b480 0x24e14c000 + 259200 2 SwiftData 0x24e193968 0x24e14c000 + 293224 3 SwiftData
Replies
9
Boosts
0
Views
862
Activity
Oct ’24
SwiftData on visionOS?
As of now, it's not listed as supported and also doesn't work. Is SwiftData not coming to visionOS?
Replies
3
Boosts
0
Views
1k
Activity
Jul ’23
Query relationship hierarchy
I have a fundamental question for Queries in CloudKit.I have a relationship structure set with references where Courses->Holes->Locations. Basically a course owns 18 holes, which each own 4 locations...Is there a way to query to find all locations beneath a given Course without querying by hole? I am trying to reduce the number of queries I have to do to CloudKit to get the information I need.Today I query to get the record for a Course, then one query for all the holes belonging to that course, then I have 18 queries for locations by hole...If I could query all locations in a course, I could reduce my queries from 20 total to 3 total. I know this is possible for a similar structure in coreData. Can't figure it out for Cloudkit.
Replies
0
Boosts
0
Views
131
Activity
Apr ’16
What is the difference between class-only protocol and protocol inherited from AnyObject?
For more information please look at this question http://stackoverflow.com/q/30176814/746347
Replies
0
Boosts
0
Views
155
Activity
Sep ’15