Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

How to inheritance Cocoapods Library to extend the functionality in the Xcode framework project
When building my iOS framework, I encountered a (fatal) module 'TrustKit' not found issue. I've marked the necessary classes as public (which is inherited from other library classes) for client applications, but I'm unsure how to resolve this error. Example Code Snippet import Foundation import TrustKit @objc public class InheritanceTruskitFrameworkProjectClass: TrustKit { func extraFunctionality() { print(extraFunctionality executing...) } } Error while building the framework in the auto-generated Swift header file (ProjectName-Swift.h) #if !defined(SWIFT_IMPORT_STDLIB_SYMBOL) # define SWIFT_IMPORT_STDLIB_SYMBOL #endif #endif #if defined(__OBJC__) #if __has_feature(objc_modules) #if __has_warning(-Watimport-in-framework-header) #pragma clang diagnostic ignored -Watimport-in-framework-header #endif @import Foundation; @import TrustKit; # -> error here `(fatal) module 'TrustKit' not found` #endif #endif #pragma clang diagnostic ignored -Wproperty-attribute-mismatch #pragma clang diagnostic ignored
0
0
568
Aug ’24
Can't see the circle buttons beside the modifier in the Attribute inspector to reset to inherited settings?
When Daisy was discussing about editing the modifiers in the Attribute inspector, she was selecting a blue circle checkbox that automatically reset the modifier to the inherited settings. However, when i'm trying it on my own. I can't see the blue circle checkbox beside each modifier. Am I missing anything in the video to make it show up? Currently using Xcode 12, MacOS Catalina 10.15.5 Thanks :)
1
0
616
Jul ’20
Reply to How to subclass with SwiftData?
@stockholmelectronica I am currently experimenting with inheritance with SwiftData and I am not yet to the point to declare if it is or it is not supported, but I have verified that adding @Model to a subclass of a @Model class makes the compiler angry: Redundant conformance of 'Subclass' to protocol 'PersistentModel' Property 'backingData' with type 'any BackingData' cannot override a property with type 'any BackingData' Cannot override static method (for schemaMetadata(), included in the Macro) With the caveat of not knowing if data will be persisted yet, what I have established so far is that it seems to be needed to add an implementation of the following method to the subclasses, but I am not sure that calling super.init will be enough: required init(backingData: any BackingData, fromFetch: Bool = false) { super.init(backingData: backingData) } Update: I am stepping away from trying to use SwiftData with inheritance: after creating a @Model parent class and a subclass w
Jun ’23
Reply to error: the replacement path doesn't exist:
I have a SwiftData document-based app with iCloud documents enabled, and lots of one-to-many @model relationships. I have the same issue as reported, and I am getting the error: Publishing changes from background threads is not allowed; make sure to publish values from the main thread I also get a crash shortly after with the breakpoint message: SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData. I wonder if the two errors are related. Both errors have only appeared in ios18, and the app has been running great for many months in ios17 with no crashes. Suddenly ios18 is released and the entire app is broken. Grrrrr.
Sep ’24
Protocol Inheritance - Function Type Override
I would like a 'child' protocol to override the types of one of the 'parent' functions. Like this:protocol Delegate {} protocol Thing { func handle (delegate: Delegate) } protocol OtherDelegate : Delegate {} protocol OtherThing : Thing { func handle (delegate: OtherDelegate) // requires OtherDelegate, not Delegate }If I then implement `OtherThing` with:class StandardOtherThing : OtherThing { // ... }It requires implementations of two `handle` functions - one for `Delegate` and one for `OtherDelegate`. It should be an error to pass `OtherThing` just a plain old `Delegate`; `OtherDelegate` is required. Can't I catch this before runtime?If instead I try parameterizing `handle` asprotocol Thing { func handle<D: Delegate> (delegate: D) } protocol OtherThing : Thing { func handle<D: OtherDelegate> (delegate: D) }still no dice, the `OtherThing` requires two methods.I know that I can use:protocol Entity { typealias D : Delegate func handle (delegate: D) } protocol OtherEntity : Entity { typealias D : Othe
1
0
443
Jan ’16
Protocol extension methods not inherited?
I find this very surprising:protocol State { func enterState () func test () } extension State { func enterState () { print (State) } func test () { enterState () } } class State0: State { } class State1: State0 { func enterState () { print (State1) } } let x = State1 () x.enterState () // prints State1 x.test () // prints StateNotice that in that last line, in method 'test' an object of class State1 invokes State.enterState (), not self.enterState (). Is this intentional or a bug?The current documentation saysIf a conforming type provides its own implementation of a required method or property, that implementation will be used instead of the one provided by the extension.To my mind, 'State1' is a conforming type, and it does provide its own implementation of 'enterState', but that implementation isn't being used.
1
0
615
Jul ’15
Reply to Finding source for SwiftData array behaviour
Yeah, that is what I mentioned above, and it's because a too-many relationship is expressed as a set (NSSet) in Core Data, which is used by SwiftData default store. I don't think the behavior is formally documented. If you don't mind, please file a feedback report. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to When to use structs with swift data?
I think your question should be a class if you want to persist it in SwiftData. I think the general advice (for SwiftData) is: structs are for views, classes are for models. Your models would be something like this: @Model final class Exam { let timestamp: Date let id: String var title: String @Relationship(deleteRule: .cascade, inverse: Question.exam) var questions: [Question] = [] init(title:String = ) { self.timestamp = .now self.id = UUID().uuidString self.title = title } } @Model final class Question { let id: String var number: Int var points: Int var prompt: String var answer: String @Relationship var exam: Exam? = nil init( number: Int = 0, points: Int = 0, prompt: String = , answer: String = ) { self.id = UUID().uuidString self.number = number self.points = points self.prompt = prompt self.answer = answer } } I hope this helps!
Jul ’24
Reply to SwiftData - Context missing for optional
I had the same issue when trying to remove a child object from a relationship directly using the context.delete method I fixed my crash by removing the object from the parent object list and saving the context. So instead of doing mainModelContext.delete(child) I am doing // get the child index from the parent parent.childs.remove(at: childIndex) mainModelContext.save() This seems to fix the crash and its also trigger update on the parent model if a view is observing it. My experience with SwiftData so far has been that if you have to modify relationships it's better to do it from parent side. I have encountered crashes or updates not triggering as expected otherwise.
Nov ’24
Core Data and Relationships
I'm trying to start a dialogue with these comments where a clear description of core data relationships can be discussed.I've been building relational databases for more than three decades, and I find it interesting that every database development environment that uses relationships has a problem in writing a clear and decisive method of using the relationships.In Xcode, things are no different where the descriptions of setting up relationships requires a PhD to understand the content being discussed. The word used to describe the relationships are uniquely Apples approach in terms. for example; reflective relationships is used to describe(This entity can be the same as the entity at the source). Most database relationships use the term primary key, and foreign key. With the primary being the parent and the foreign key being the child relationship. In Apples description there is no reference to a parent or child relationship.What I'm trying to do
0
0
595
Sep ’15
Constraining an associated type from an inherited protocol?
Writing constrained versions of existing protocols seems like a basic and useful thing to do, yet I keep running into problems when trying. I'll try to explain what I mean by an example:Let's say we need a protocol that is exactly like GeneratorType except that its Element must be an IntegerType.I might be missing something but I'm guessing that this is the way to express that in Swift:protocol IntegerGeneratorType : GeneratorType { typealias Element: IntegerType }We could make a GeneratorType based protocol with even harder constraints on its Element, eg that it must be Int:protocol IntGeneratorType : GeneratorType { typealias Element = Int }Now, let's add a default implementation of a method called squaredNext to the latter example protocol:extension IntGeneratorType { mutating func squaredNext() -> Int? { guard let someNext = next() else { return nil } return someNext * someNext // Error: Binary operator '*' cannot be applied to two 'Self.Element' operands. } }I can't see the reason for that error. It s
2
0
2.1k
Nov ’15
Is inheritance different from other languages in swift
superVC:sSuperVCoverride func viewDidLoad() { super.viewDidLoad() setupUI()}override func setupUI() { print(123)}subVC:superVCverride func viewDidLoad() { super.viewDidLoad()}override func setupUI() { print(456)}subVC()when push subVCwhy its log 456 ,,,,its strangelog info * frame #0: 0x00000001001abce4 superVC.setupUI(self=0x0000000157ef0620) at superVC.swift:42 frame #1: 0x00000001003a8340 subVC.viewDidLoad(self=0x0000000157ef0620) at subVC.swift:69 frame #2: 0x00000001003a8a9c subVC.viewDidLoad() at <compiler-generated>:0 frame #3: 0x00000001001abc0c superVC.viewDidLoad(self=0x0000000157ef0620) at superVCswift:36 frame #4: 0x00000001001abcb0 superVC.viewDidLoad() at <compiler-generated>:0
1
0
731
Oct ’18
Convenience initializer inheritance issue
I simplified my code that was getting the error into the following in order to show what the issue is. The problem seems to happen in subclasses of generics. Copy and past the code into a playground and you shoudl get the same results.class MyClass { convenience init?(succeed:Bool) { guard succeed else {return nil} self.init() } init(){} } class MySubClass:MyClass {} class MyGenericClass<T> { convenience init?(succeed:T) { guard succeed as? Bool ?? false else {return nil} self.init() } init(){} } class MyGenericSubClass<T>:MyGenericClass<T> {} class MyTypedGenericSubClass:MyGenericClass<Bool> {} MyClass(succeed: true) // Works MySubClass(succeed: true) // Works MyGenericClass<Bool>(succeed: true) // Works MyGenericSubClass<Bool>(succeed: true) // Fails MyTypedGenericSubClass(succeed: true) // Fails /* Gets the following error: Playground execution failed: error: MyPlayground.playground:59:1: error: '(Bool) -> MyGenericSubClass<Bool>' is not convertible to '(Bool) -
1
0
453
Jan ’17
Endpoint security inherited mute
I am developing an app that uses the Endpoint Security API. I need to mute a few processes like: my own process, xcode, etc' ... However, if the muted processes create child processes, I want these processes to be muted as well. The full process tree under muted processes should be muted. How can that be done? Cant see in docs and can't find an example. If it can't be done, whats the closest thing to that I can implement. Thanks!
1
0
645
Mar ’24
How to inheritance Cocoapods Library to extend the functionality in the Xcode framework project
When building my iOS framework, I encountered a (fatal) module 'TrustKit' not found issue. I've marked the necessary classes as public (which is inherited from other library classes) for client applications, but I'm unsure how to resolve this error. Example Code Snippet import Foundation import TrustKit @objc public class InheritanceTruskitFrameworkProjectClass: TrustKit { func extraFunctionality() { print(extraFunctionality executing...) } } Error while building the framework in the auto-generated Swift header file (ProjectName-Swift.h) #if !defined(SWIFT_IMPORT_STDLIB_SYMBOL) # define SWIFT_IMPORT_STDLIB_SYMBOL #endif #endif #if defined(__OBJC__) #if __has_feature(objc_modules) #if __has_warning(-Watimport-in-framework-header) #pragma clang diagnostic ignored -Watimport-in-framework-header #endif @import Foundation; @import TrustKit; # -> error here `(fatal) module 'TrustKit' not found` #endif #endif #pragma clang diagnostic ignored -Wproperty-attribute-mismatch #pragma clang diagnostic ignored
Replies
0
Boosts
0
Views
568
Activity
Aug ’24
Can't see the circle buttons beside the modifier in the Attribute inspector to reset to inherited settings?
When Daisy was discussing about editing the modifiers in the Attribute inspector, she was selecting a blue circle checkbox that automatically reset the modifier to the inherited settings. However, when i'm trying it on my own. I can't see the blue circle checkbox beside each modifier. Am I missing anything in the video to make it show up? Currently using Xcode 12, MacOS Catalina 10.15.5 Thanks :)
Replies
1
Boosts
0
Views
616
Activity
Jul ’20
Reply to @Model and Encodable cause the error Ambiguous use of 'setValue(for:to:)'
I'm not coming in with a solution, but just to say that I'm seeing the exact same error. SwiftData unfortunately seems to be very poorly rolled out so far, even for a beta. Editing to add: it seems as if I'm only getting those errors on attributes marked with the @Relationship marker.
Replies
Boosts
Views
Activity
Jun ’23
Reply to How to subclass with SwiftData?
@stockholmelectronica I am currently experimenting with inheritance with SwiftData and I am not yet to the point to declare if it is or it is not supported, but I have verified that adding @Model to a subclass of a @Model class makes the compiler angry: Redundant conformance of 'Subclass' to protocol 'PersistentModel' Property 'backingData' with type 'any BackingData' cannot override a property with type 'any BackingData' Cannot override static method (for schemaMetadata(), included in the Macro) With the caveat of not knowing if data will be persisted yet, what I have established so far is that it seems to be needed to add an implementation of the following method to the subclasses, but I am not sure that calling super.init will be enough: required init(backingData: any BackingData, fromFetch: Bool = false) { super.init(backingData: backingData) } Update: I am stepping away from trying to use SwiftData with inheritance: after creating a @Model parent class and a subclass w
Replies
Boosts
Views
Activity
Jun ’23
Reply to error: the replacement path doesn't exist:
I have a SwiftData document-based app with iCloud documents enabled, and lots of one-to-many @model relationships. I have the same issue as reported, and I am getting the error: Publishing changes from background threads is not allowed; make sure to publish values from the main thread I also get a crash shortly after with the breakpoint message: SwiftData/ModelContext.swift:3253: Fatal error: Failed to identify a store that can hold instances of SwiftData. I wonder if the two errors are related. Both errors have only appeared in ios18, and the app has been running great for many months in ios17 with no crashes. Suddenly ios18 is released and the entire app is broken. Grrrrr.
Replies
Boosts
Views
Activity
Sep ’24
Protocol Inheritance - Function Type Override
I would like a 'child' protocol to override the types of one of the 'parent' functions. Like this:protocol Delegate {} protocol Thing { func handle (delegate: Delegate) } protocol OtherDelegate : Delegate {} protocol OtherThing : Thing { func handle (delegate: OtherDelegate) // requires OtherDelegate, not Delegate }If I then implement `OtherThing` with:class StandardOtherThing : OtherThing { // ... }It requires implementations of two `handle` functions - one for `Delegate` and one for `OtherDelegate`. It should be an error to pass `OtherThing` just a plain old `Delegate`; `OtherDelegate` is required. Can't I catch this before runtime?If instead I try parameterizing `handle` asprotocol Thing { func handle<D: Delegate> (delegate: D) } protocol OtherThing : Thing { func handle<D: OtherDelegate> (delegate: D) }still no dice, the `OtherThing` requires two methods.I know that I can use:protocol Entity { typealias D : Delegate func handle (delegate: D) } protocol OtherEntity : Entity { typealias D : Othe
Replies
1
Boosts
0
Views
443
Activity
Jan ’16
Protocol extension methods not inherited?
I find this very surprising:protocol State { func enterState () func test () } extension State { func enterState () { print (State) } func test () { enterState () } } class State0: State { } class State1: State0 { func enterState () { print (State1) } } let x = State1 () x.enterState () // prints State1 x.test () // prints StateNotice that in that last line, in method 'test' an object of class State1 invokes State.enterState (), not self.enterState (). Is this intentional or a bug?The current documentation saysIf a conforming type provides its own implementation of a required method or property, that implementation will be used instead of the one provided by the extension.To my mind, 'State1' is a conforming type, and it does provide its own implementation of 'enterState', but that implementation isn't being used.
Replies
1
Boosts
0
Views
615
Activity
Jul ’15
Reply to Finding source for SwiftData array behaviour
Yeah, that is what I mentioned above, and it's because a too-many relationship is expressed as a set (NSSet) in Core Data, which is used by SwiftData default store. I don't think the behavior is formally documented. If you don't mind, please file a feedback report. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’25
Reply to When to use structs with swift data?
I think your question should be a class if you want to persist it in SwiftData. I think the general advice (for SwiftData) is: structs are for views, classes are for models. Your models would be something like this: @Model final class Exam { let timestamp: Date let id: String var title: String @Relationship(deleteRule: .cascade, inverse: Question.exam) var questions: [Question] = [] init(title:String = ) { self.timestamp = .now self.id = UUID().uuidString self.title = title } } @Model final class Question { let id: String var number: Int var points: Int var prompt: String var answer: String @Relationship var exam: Exam? = nil init( number: Int = 0, points: Int = 0, prompt: String = , answer: String = ) { self.id = UUID().uuidString self.number = number self.points = points self.prompt = prompt self.answer = answer } } I hope this helps!
Replies
Boosts
Views
Activity
Jul ’24
Reply to SwiftData - Context missing for optional
I had the same issue when trying to remove a child object from a relationship directly using the context.delete method I fixed my crash by removing the object from the parent object list and saving the context. So instead of doing mainModelContext.delete(child) I am doing // get the child index from the parent parent.childs.remove(at: childIndex) mainModelContext.save() This seems to fix the crash and its also trigger update on the parent model if a view is observing it. My experience with SwiftData so far has been that if you have to modify relationships it's better to do it from parent side. I have encountered crashes or updates not triggering as expected otherwise.
Replies
Boosts
Views
Activity
Nov ’24
Core Data and Relationships
I'm trying to start a dialogue with these comments where a clear description of core data relationships can be discussed.I've been building relational databases for more than three decades, and I find it interesting that every database development environment that uses relationships has a problem in writing a clear and decisive method of using the relationships.In Xcode, things are no different where the descriptions of setting up relationships requires a PhD to understand the content being discussed. The word used to describe the relationships are uniquely Apples approach in terms. for example; reflective relationships is used to describe(This entity can be the same as the entity at the source). Most database relationships use the term primary key, and foreign key. With the primary being the parent and the foreign key being the child relationship. In Apples description there is no reference to a parent or child relationship.What I'm trying to do
Replies
0
Boosts
0
Views
595
Activity
Sep ’15
Constraining an associated type from an inherited protocol?
Writing constrained versions of existing protocols seems like a basic and useful thing to do, yet I keep running into problems when trying. I'll try to explain what I mean by an example:Let's say we need a protocol that is exactly like GeneratorType except that its Element must be an IntegerType.I might be missing something but I'm guessing that this is the way to express that in Swift:protocol IntegerGeneratorType : GeneratorType { typealias Element: IntegerType }We could make a GeneratorType based protocol with even harder constraints on its Element, eg that it must be Int:protocol IntGeneratorType : GeneratorType { typealias Element = Int }Now, let's add a default implementation of a method called squaredNext to the latter example protocol:extension IntGeneratorType { mutating func squaredNext() -> Int? { guard let someNext = next() else { return nil } return someNext * someNext // Error: Binary operator '*' cannot be applied to two 'Self.Element' operands. } }I can't see the reason for that error. It s
Replies
2
Boosts
0
Views
2.1k
Activity
Nov ’15
Is inheritance different from other languages in swift
superVC:sSuperVCoverride func viewDidLoad() { super.viewDidLoad() setupUI()}override func setupUI() { print(123)}subVC:superVCverride func viewDidLoad() { super.viewDidLoad()}override func setupUI() { print(456)}subVC()when push subVCwhy its log 456 ,,,,its strangelog info * frame #0: 0x00000001001abce4 superVC.setupUI(self=0x0000000157ef0620) at superVC.swift:42 frame #1: 0x00000001003a8340 subVC.viewDidLoad(self=0x0000000157ef0620) at subVC.swift:69 frame #2: 0x00000001003a8a9c subVC.viewDidLoad() at <compiler-generated>:0 frame #3: 0x00000001001abc0c superVC.viewDidLoad(self=0x0000000157ef0620) at superVCswift:36 frame #4: 0x00000001001abcb0 superVC.viewDidLoad() at <compiler-generated>:0
Replies
1
Boosts
0
Views
731
Activity
Oct ’18
Convenience initializer inheritance issue
I simplified my code that was getting the error into the following in order to show what the issue is. The problem seems to happen in subclasses of generics. Copy and past the code into a playground and you shoudl get the same results.class MyClass { convenience init?(succeed:Bool) { guard succeed else {return nil} self.init() } init(){} } class MySubClass:MyClass {} class MyGenericClass<T> { convenience init?(succeed:T) { guard succeed as? Bool ?? false else {return nil} self.init() } init(){} } class MyGenericSubClass<T>:MyGenericClass<T> {} class MyTypedGenericSubClass:MyGenericClass<Bool> {} MyClass(succeed: true) // Works MySubClass(succeed: true) // Works MyGenericClass<Bool>(succeed: true) // Works MyGenericSubClass<Bool>(succeed: true) // Fails MyTypedGenericSubClass(succeed: true) // Fails /* Gets the following error: Playground execution failed: error: MyPlayground.playground:59:1: error: '(Bool) -> MyGenericSubClass<Bool>' is not convertible to '(Bool) -
Replies
1
Boosts
0
Views
453
Activity
Jan ’17
Endpoint security inherited mute
I am developing an app that uses the Endpoint Security API. I need to mute a few processes like: my own process, xcode, etc' ... However, if the muted processes create child processes, I want these processes to be muted as well. The full process tree under muted processes should be muted. How can that be done? Cant see in docs and can't find an example. If it can't be done, whats the closest thing to that I can implement. Thanks!
Replies
1
Boosts
0
Views
645
Activity
Mar ’24