Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Reply to migrating common code to one place
We are getting into object oriented design philosophy here. Describe what those routines do in natural language. If the relationship between your two UIViews and the common stuff is is a, use inheritance to make your two UIView subclasses extend from a common base class. If it's has a, use composition - move the common functionality into a separate class, an instance of which each of your two UIViews would contain.
Jul ’16
SwiftData @Query crashes when trying to filter or sort using an enum or relationship
Like the title says, I've realised that when I try to use filter or sort on properties that aren't standard supported data types i.e. Using a transformable or a value type like an enum, I seem to be getting the following crash... SwiftData/DataUtilities.swift:1140: Fatal error: Unexpected type for Expansion: Optional Xcode expands and shows me when trying to access the wrapped value it's crashing. I'm assumung that the query property wrapper can't handle these custom data types @Query private var items: [Item] { get { _items.wrappedValue <--- Crash here } } Which seems to be pointing to a transferable property in one of my models. Below are my two models i'm using. enum Priority: Int, Codable, Identifiable, CaseIterable { case low case medium case high var title: String { switch self { case .low: return Low case .medium: return Medium case .high: return High } } var image: Image? { switch self { case .medium: return Image(systemName: exclamationmark.2) case .high: return Image(systemName: exclamat
8
0
3.4k
Sep ’23
Extension with constraints cannot have an inheritance clause?
struct Wrapper<Value> { let value : Value } extension Wrapper : Equatable where Value : Equatable { static func ==(lhs: Wrapper, rhs: Wrapper) -> Bool { return lhs.value == rhs.value } }Entering the above code in a Playground in Xcode Version 9.0 beta (9M136h) gives the following error:error: MyPlayground.playground:1:1: error: extension of type 'Wrapper' with constraints cannot have an inheritance clauseextension Wrapper : Equatable where Value : Equatable {Isn't this supposed to work in Swift 4?
3
0
2.1k
Jun ’17
Reply to Error when running a modelContext rollback
Hi - I am getting the same error, but on modelContext.delete(). I went through checking all the relationship ids, and they are all fine. All models seem to be registered and can be accessed through relationships, fetches or @Query. . I have had some success with SwiftData, using in a semi-production app for about a year. I have never seen this error message before. This seems like a new bug to me.
May ’25
protocol inheritance
I have a couple of issues. The first is I want to be able to do thisprotocol A { static func someMethod() -> Self?}extension A { static func someMethod() -> Self? { ... }}protocal B: A {}extension B { static func someMethod() -> Self? { ... call protocol A's someMethod ... }}Is there a way to do this? I need to add some additional behavior to protocol B and do all of the code in protocol A's protocol extension. The best I could cope up with is have exension A have a doSomeMethod() method that does the actual work, then have both A and B call that. Is there a way to do the equivalent of super.someMethod() which doesn't work because it's not a class.
9
0
1.5k
Aug ’15
Inheriting from an objective-c static class in Swift
It might be a trivial issue, but I am not able to solve it. I have the following function in an objective-c superclass:+(instancetype) lineWithNumber: (NSString*)number;and I am trying to inherit in a swift subclass with:class func lineWithNumber(number:NSString)->LineYet if I put the override in front I get error:Method does not override any method from its superclassif on the other hand I omit the override keyword it reports:Method 'lineWithNumber' with Objective-C selector 'lineWithNumber:' conflicts with method 'lineWithNumber' from superclass 'Line' with the same Objective-C selectorI also tried replacing instancetype with Line as in the inheited function with no change.Calls in other classe would regularly access the Swift function if it were not for the error. What might be the problem, and is there a way to check how Xcode translates Objective-c signatures when they are imported in Swift?
7
0
2.7k
Dec ’15
Reply to SwiftData relationship crash on 17.x
Adding @Relationship before a relationship is fine, unless you specify the inverse parameter on both side, which will then trigger an error. The error shown in your screenshot doesn't seem to be related to the existence of @Relationship in Summary. It is more likely related to the way you set up the object graph, which may be similar to the following post: SwiftData inverse relationship not updating If the above post doesn't help, I'd be interested in taking a closer look into your code that reproduces the issue, if you don't mind to share that. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Oct ’24
Subclass inherit from class not able to access properties
I have defined the following class and subclass:import Foundation class Node { var key : String private weak var parent: Node? private var children: [Node] = [] init(key : String) { self.key = key } func addChildNode(child: Node) { children.append(child) child.parent = self } func rootNode() -> Node { var node = self while node.parent != nil { node = node.parent! } return node } } class SubNode : Node { var time : [Double] = [] }When using the subclass and the method rootNode inherited, this returns the class Node and not the subclass SubNode. Therefore, I can not access the time property. One option is of course to cast explicitily the outcome of the rootNode as SubNode. But this is not very elegant. Any other idea?var a = SubNode(key: a) a.time = [11,2,3] var b = SubNode(key: b) var c = SubNode(key: c) a.addChildNode(b) b.addChildNode(c) c.rootNode() // c.rootNode can not access time unles casted as SubNode
3
0
3.6k
Sep ’16
Cannot use Hypervisor with inherited app sandbox
I have a main app with the entitlements: com.apple.security.app-sandbox com.apple.security.hypervisor and a helper app with the entitlements com.apple.security.app-sandbox com.apple.security.inherit According to the documentations, if I start the helper app with NSTask, it should inherit the sandbox and I do see that for file accesses. However, when I try to use Hypervisor.framework, I get HV_DENIED. If I try to add com.apple.security.hypervisor to the helper app, then the NSTask spawned process crashes with Could not set sandbox profile data: Operation not permitted (1). I believe this is a bug and have submitted FB8921623 In the meantime, is there a workaround other than disabling App Sandbox or sticking to a single app (not possible for our application)?
1
0
909
Dec ’20
SwiftData how to release the relationship data after popping the view back
ViewA has ModelA ViewA loads into the memory. ModelA is queried and shown in the list. ModelA has an array of ModelB which is faulted for the memory. When you select an item in the list in ViewA ViewB is loaded and ModelB information is displayed. When you pop back to ViewA, ModelB is still in the memory since it is contained within the array of ModelA. how could i make this memory efficient by releasing ModelB from the memory. should I refetch everything? or is there another method?
1
0
499
Feb ’24
Re: Resolving App Sandbox Inheritance Problems
I have a werid case that shouldn't happen according to https://forums.developer.apple.com/forums/thread/706390 I have an audio unit which runs in FCP and I want it to launch a sandboxed app as a child process. If I sign the child app with just com.apple.security.app-sandbox entitlement it crashes with SYSCALL_SET_PROFILE error. According to the article referenced above: This indicates that the process tried to setup its sandbox profile but that failed, in this case because it already has a sandbox profile. This makes sense because audio units run in a sandboxed environment (in AUHostingService process). So I added com.apple.security.inherit to the entitlements plist and now I get Process is not in an inherited sandbox. error. According to the article referenced above: Another cause of a trap within _libsecinit_appsandbox is when a nonsandboxed process runs another program as a child process and that other program’s executable has the com.apple.security.app-sandbox and com.apple.security.inherit entit
3
0
912
Dec ’24
Reply to migrating common code to one place
We are getting into object oriented design philosophy here. Describe what those routines do in natural language. If the relationship between your two UIViews and the common stuff is is a, use inheritance to make your two UIView subclasses extend from a common base class. If it's has a, use composition - move the common functionality into a separate class, an instance of which each of your two UIViews would contain.
Replies
Boosts
Views
Activity
Jul ’16
Reply to Using relationships in SortDescriptor crashing on release
@DTS Engineer the issue @Ches Beiner brought up is still an issue, as detailed in my post on the thread you linked to: SwiftData crash when using a @Query sort descriptor with a relationship
Replies
Boosts
Views
Activity
Aug ’25
SwiftData @Query crashes when trying to filter or sort using an enum or relationship
Like the title says, I've realised that when I try to use filter or sort on properties that aren't standard supported data types i.e. Using a transformable or a value type like an enum, I seem to be getting the following crash... SwiftData/DataUtilities.swift:1140: Fatal error: Unexpected type for Expansion: Optional Xcode expands and shows me when trying to access the wrapped value it's crashing. I'm assumung that the query property wrapper can't handle these custom data types @Query private var items: [Item] { get { _items.wrappedValue <--- Crash here } } Which seems to be pointing to a transferable property in one of my models. Below are my two models i'm using. enum Priority: Int, Codable, Identifiable, CaseIterable { case low case medium case high var title: String { switch self { case .low: return Low case .medium: return Medium case .high: return High } } var image: Image? { switch self { case .medium: return Image(systemName: exclamationmark.2) case .high: return Image(systemName: exclamat
Replies
8
Boosts
0
Views
3.4k
Activity
Sep ’23
Extension with constraints cannot have an inheritance clause?
struct Wrapper<Value> { let value : Value } extension Wrapper : Equatable where Value : Equatable { static func ==(lhs: Wrapper, rhs: Wrapper) -> Bool { return lhs.value == rhs.value } }Entering the above code in a Playground in Xcode Version 9.0 beta (9M136h) gives the following error:error: MyPlayground.playground:1:1: error: extension of type 'Wrapper' with constraints cannot have an inheritance clauseextension Wrapper : Equatable where Value : Equatable {Isn't this supposed to work in Swift 4?
Replies
3
Boosts
0
Views
2.1k
Activity
Jun ’17
Reply to Error when running a modelContext rollback
Hi - I am getting the same error, but on modelContext.delete(). I went through checking all the relationship ids, and they are all fine. All models seem to be registered and can be accessed through relationships, fetches or @Query. . I have had some success with SwiftData, using in a semi-production app for about a year. I have never seen this error message before. This seems like a new bug to me.
Replies
Boosts
Views
Activity
May ’25
Reply to SwiftData crash when using a @Query sort descriptor with a relationship
@DTS Engineer Any recommendations for this behavior? Working with @Query and @Relationship is a standard practice with SwiftData, but we are going to face live issues without support from Apple on this regression as adoption grows rapidly.
Replies
Boosts
Views
Activity
Feb ’25
Reply to Fetching data with relationships directly faults the relationships even when not accessed
Here is a simple test project: https://github.com/GNiewoehner/swiftdata-test-app On start it creates some dummy data, and fetches them without accessing any relationships. The logs are printed to the console.
Replies
Boosts
Views
Activity
May ’25
protocol inheritance
I have a couple of issues. The first is I want to be able to do thisprotocol A { static func someMethod() -> Self?}extension A { static func someMethod() -> Self? { ... }}protocal B: A {}extension B { static func someMethod() -> Self? { ... call protocol A's someMethod ... }}Is there a way to do this? I need to add some additional behavior to protocol B and do all of the code in protocol A's protocol extension. The best I could cope up with is have exension A have a doSomeMethod() method that does the actual work, then have both A and B call that. Is there a way to do the equivalent of super.someMethod() which doesn't work because it's not a class.
Replies
9
Boosts
0
Views
1.5k
Activity
Aug ’15
Reply to SwiftData "Auto Inserts" array into ModelContext
SwiftData does it automatically for you and it must do it or the autosave functionality wouldn't work. If you would only save one side of a relationship then when the app is restarted the other side would be nil or it crashes if the property is non-optional.
Replies
Boosts
Views
Activity
Apr ’25
Inheriting from an objective-c static class in Swift
It might be a trivial issue, but I am not able to solve it. I have the following function in an objective-c superclass:+(instancetype) lineWithNumber: (NSString*)number;and I am trying to inherit in a swift subclass with:class func lineWithNumber(number:NSString)->LineYet if I put the override in front I get error:Method does not override any method from its superclassif on the other hand I omit the override keyword it reports:Method 'lineWithNumber' with Objective-C selector 'lineWithNumber:' conflicts with method 'lineWithNumber' from superclass 'Line' with the same Objective-C selectorI also tried replacing instancetype with Line as in the inheited function with no change.Calls in other classe would regularly access the Swift function if it were not for the error. What might be the problem, and is there a way to check how Xcode translates Objective-c signatures when they are imported in Swift?
Replies
7
Boosts
0
Views
2.7k
Activity
Dec ’15
Reply to SwiftData relationship crash on 17.x
Adding @Relationship before a relationship is fine, unless you specify the inverse parameter on both side, which will then trigger an error. The error shown in your screenshot doesn't seem to be related to the existence of @Relationship in Summary. It is more likely related to the way you set up the object graph, which may be similar to the following post: SwiftData inverse relationship not updating If the above post doesn't help, I'd be interested in taking a closer look into your code that reproduces the issue, if you don't mind to share that. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Replies
Boosts
Views
Activity
Oct ’24
Subclass inherit from class not able to access properties
I have defined the following class and subclass:import Foundation class Node { var key : String private weak var parent: Node? private var children: [Node] = [] init(key : String) { self.key = key } func addChildNode(child: Node) { children.append(child) child.parent = self } func rootNode() -> Node { var node = self while node.parent != nil { node = node.parent! } return node } } class SubNode : Node { var time : [Double] = [] }When using the subclass and the method rootNode inherited, this returns the class Node and not the subclass SubNode. Therefore, I can not access the time property. One option is of course to cast explicitily the outcome of the rootNode as SubNode. But this is not very elegant. Any other idea?var a = SubNode(key: a) a.time = [11,2,3] var b = SubNode(key: b) var c = SubNode(key: c) a.addChildNode(b) b.addChildNode(c) c.rootNode() // c.rootNode can not access time unles casted as SubNode
Replies
3
Boosts
0
Views
3.6k
Activity
Sep ’16
Cannot use Hypervisor with inherited app sandbox
I have a main app with the entitlements: com.apple.security.app-sandbox com.apple.security.hypervisor and a helper app with the entitlements com.apple.security.app-sandbox com.apple.security.inherit According to the documentations, if I start the helper app with NSTask, it should inherit the sandbox and I do see that for file accesses. However, when I try to use Hypervisor.framework, I get HV_DENIED. If I try to add com.apple.security.hypervisor to the helper app, then the NSTask spawned process crashes with Could not set sandbox profile data: Operation not permitted (1). I believe this is a bug and have submitted FB8921623 In the meantime, is there a workaround other than disabling App Sandbox or sticking to a single app (not possible for our application)?
Replies
1
Boosts
0
Views
909
Activity
Dec ’20
SwiftData how to release the relationship data after popping the view back
ViewA has ModelA ViewA loads into the memory. ModelA is queried and shown in the list. ModelA has an array of ModelB which is faulted for the memory. When you select an item in the list in ViewA ViewB is loaded and ModelB information is displayed. When you pop back to ViewA, ModelB is still in the memory since it is contained within the array of ModelA. how could i make this memory efficient by releasing ModelB from the memory. should I refetch everything? or is there another method?
Replies
1
Boosts
0
Views
499
Activity
Feb ’24
Re: Resolving App Sandbox Inheritance Problems
I have a werid case that shouldn't happen according to https://forums.developer.apple.com/forums/thread/706390 I have an audio unit which runs in FCP and I want it to launch a sandboxed app as a child process. If I sign the child app with just com.apple.security.app-sandbox entitlement it crashes with SYSCALL_SET_PROFILE error. According to the article referenced above: This indicates that the process tried to setup its sandbox profile but that failed, in this case because it already has a sandbox profile. This makes sense because audio units run in a sandboxed environment (in AUHostingService process). So I added com.apple.security.inherit to the entitlements plist and now I get Process is not in an inherited sandbox. error. According to the article referenced above: Another cause of a trap within _libsecinit_appsandbox is when a nonsandboxed process runs another program as a child process and that other program’s executable has the com.apple.security.app-sandbox and com.apple.security.inherit entit
Replies
3
Boosts
0
Views
912
Activity
Dec ’24