Search results for

“SwiftData inheritance relationship”

4,980 results found

Post

Replies

Boosts

Views

Activity

Generic constraints with non-protocol types
It would be great if we could write generic constraints which are expressed in terms of other generic constraints. It would allow us to create much more powerful constructs with greater expressiveness to the type-system.One example which would be helpful:enum Either<T1,T2> { case A( T1 ) case B( T2 ) func asCommonType<T where T1:T, T2:T>( type: T.Type ) -> T { switch self { case .A( let val ): return val as! T case .B( let val ): return val as! T } } }Then I could use the Either type like this:let someView : Either<UIButton, UIImageView> ... view.addSubview( someView.asCommonType( UIView.Type ) )With compile-time guarantees which restrict the types that someView may be assigned, and also when it is used that it may be represented as a UIView. If anybody changes the code in a way which violates this relationship, it won't compile.Currently this isn't possible, as the compiler complains on line 06 that T isn't a protocol type. I can't represent this type relationship stati
6
0
8.3k
Jul ’15
Core Data & iCloud Error: Unable to find relationship destination object
Stackoverflow link: http://stackoverflow.com/questions/31695187/core-data-icloud-error-unable-to-find-relationship-destination-objectI´ve been using Core Data and iCloud for a while in my app now. But its suddenly acting up like crazy. The problem is when a device should import new changes from iCloud i.e in the- (void)persistentStoreDidImportUbiquitousContentChanges:(NSNotification *)notificationIf I add 1 new entity on device A the entity will sync over to device B. But if I add multiple new entities at the same time only the one or two last will sync over to device B. This is when I get the error message:Unable to find relationship destination object: [_PFUbiquityRecordImportOperation processObjects:withState:andImportContext:outError:](1017): CoreData: Ubiquity: <_PFUbiquityRecordImportOperation: 0x14694540>{name = '(null)'}I am also printing whats about to change (the [notification userInfo]) and it looks like this when following that error message.{ deleted = {(n)}; inserted = {(
0
0
402
Jul ’15
Reply to Generic constraints with non-protocol types
That's really not a solution to anything, and the whole idea of adding junk dummy protocols around your project just to work around the type system is really abhorrent to me.That dummy protocol is a guarantee of nothing. Anybody could add comformance to that protocol, and then totally defeat the type constraints I've built in to my components. I would need to flesh out that protocol with the specific methods I need (like removeFromSuperview), and I'd need to write shims for every method I need which accepts a concrete type and relies on inheritance for specialisation. Essentially, I would need to rewrite UIView as a protocol. And even then it would be horribly unsafe - somebody could just go ahead and write:extension String : ViewMaster {}and then they'd defeat all of your type guarantees and lose all of the information that those type constraints give.In this case, you might know never to make String conform to ViewMaster. In other cases, you might not be aware of all of the implications of that con
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to Generic constraints with non-protocol types
junk dummy protocols are actually known as marker protocols. They won't be necessary when Swift allows us to extend existing type with attributes.I don't know what you mean by this:Anybody could add comformance to that protocol, and then totally defeat the type constraints I've built in to my components. I would need to flesh out that protocol with the specific methods I need (like removeFromSuperview), and I'd need to write shims for every method I need which accepts a concrete type and relies on inheritance for specialisation.No programming language yet provides the amount of static analysis necessary for everyone's needs.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’15
Reply to How do we write type specific extensions to Array?
You can constrain it to your own protocol type, but if you want to append you (as noted by OOPer) have to create the right type to append. Unless your protocol includes an init or some other method that returns Self there is no way for you to do that. IntegerType DOES have such a method: it inherits from IntegerLiteralConvertible, so the integer literals you were appending could be constructed as the correct type depending on whether, for example, the array was [Int] or [UInt8] or whatever.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’15
Remove recently added view
Hi,I have a tabbarcontroller based app. In one tab, there is a navigationcontroller and various view controllers that get pushed onto it via storyboard segues.I'm attempting to create a semi-transparent overlay for help instructions. The plan was to make a detached UIViewController with an UIImageView (the help text and arrows) and a button to dismiss it. This help/tutorial view would be created in the first view controller (the normal UI for the user if they do not want help overlays) which is connected to the navigation controller via a relationship segue. The tutorial view is then added as a subview.I can get the overlay portion working and the button receives the taps well enough. It's removing the view in favor of the old view which is problematic.Here is the code in the regular UI view controller that creates the controller for the tutorial overlay and then adds its view:TutorialsAddItemsViewController* tv = [self.storyboard instantiateViewControllerWithIdentifier:@tutorial]; [self.navigationCo
Topic: UI Frameworks SubTopic: UIKit Tags:
5
0
2.9k
Aug ’15
Reply to Compiler crash with protocol extension
I have tried this:extension Optional: HashValue where T: Hashable { func hashValue() -> Int { switch self { case let .Some(t): return t.hashValue case .None: return 1 } } }But that gives the error:Extension of type 'Optional' with constraints cannot have an inheritance clauseDid you have something else in mind.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’15
Recursive entities
I have a Bracket entity that contains some number of Match entities, so that's a simple 1 to many relationship. On Match though, I now want to point to the next winner match and the next loser match, plus a couple other options (I have 4 destination matches). How do I do that and still handle the fact Core Data wants pointers to the source entity.
1
0
181
Aug ’15
predicate search on array with Core date Entity with NSDates for just a given calendar unit in date.
i have an array of entities with date objects in relationship end. I know how to filter out objects for given dates or date ranges using predicates. my situation is that now i need to filter out objects matching a given value of a calendar unit. like year 2001 or month 4.now for year this seems simple cause i can just make a start date and end date with jan 1 and dec 31 for given year. but for month week this is an impossible task to calulate start and end dates of each week or even months as there are leap years. there has to be a simpler way where i can just mention in the predicate as to which date component i want to be matched. please let me know how to do it.thanks.
Topic: UI Frameworks SubTopic: UIKit Tags:
8
0
1.8k
Aug ’15
Reply to App Store icon on lockscreen
In the old version of the forums, a user posted the answer they got from Developer Support:https://devforums.apple.com/message/1067418#1067418 Location relevant Apps are recommended on the lock screen and in the App Store based on a number of factors, including their popularity at the location, and there is no mechanism or process by which an App developer can add their App to the list of recommended Apps. However, if your iOS App is directly related to the location or venue (such as a mall guide iOS App which is published by the mall owner or operator), and you believe your iOS App’s relevance warrants it being included the list of recommended Apps, then you are encouraged to submit an enhancement request via http://bugreport.apple.com/, and request that Apple consider whether your iOS App should be included in the list of recommended Apps for that location. You should provide as much detail in the ’enhancement request' about the App and venue/location as possible, such as the App ID, App Name, URL to the Ap
Aug ’15
Protocol extension to bridge static and dynamic type worlds
I can write global functions to evaluate hashValues, e.g.:func hashValueHashable<T: Hashable>(h: T) -> Int { // Pointless because of static dispatching! return h.hashValue } func hashValueNonHashable(a: Any) -> Int { if let a = a as? AnyObject { return ObjectIdentifier(a).hashValue } return 0 }But this isn't very satisfactory because I need to manually specify which version, i.e. no dynamic dispatch.Therefore I tried to work out how to do something similar using extensions. My 1st try was extending `Any`:extension Any: Hashable { // Error: Non-nominal type `Any` cannot be extended var hashValue: Int { if let self = self as AnyObject { return ObjectIdentifier(self).hashValue } return 0 } }No luck. How about `AnyObject`?extension AnyObject: Hashable { // Error: `AnyObject` protocol cannot be extended var hashValue: Int { return ObjectIdentifier(self).hashValue } }No luck again. How about `Hashable`?extension Hashable where Self: AnyObject { var hashValue: Int { return ObjectIdentifier(self).hashValu
1
0
1.3k
Aug ’15
Reply to Recursive entities
You do exactly what you'd do in any other case:Create a new relationship on Match, and specify that the type is Match.Naturally, you'll want to specify that the relationship is optional (since not every Match will have a next winner match or a next loser match).If tracking the inverse of the four different destination matches is inconvenient, don't specify an inverse for those relationships.
Aug ’15
Reply to Protocol Oriented Programming boilerplate code
I think there's more going on here than you think.What you're really asking for is inheritance, which currently does not exist for value types. Protocol extensions are vaguely similar to inheritance in some ways, but not currently so far as to allow you to have default stored properties.You could use inheritance if your columns were classes instead of structs. Indeed, in this case, I think it's clear that your columns should be classes instead of structs. Generally, structs are inappropriate when their value represents the state of some thing, whether it's a real world object or a specific entity like a column (presumable of some table or list). In this case, a particular column has one true name, presumably along with other one true properties that you haven't shown us. If the column's one true state is immutable, it doesn't really matter whether it's a value type or a reference type, but if it's mutable as yours seems likely to be, then it's almost certainly better to use a refere
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’15
Reply to Ordering z-values of all objects in a layer, help!
I assume you have a way to get to the SKSpriteNode for each monster. To adjust the z-value, you'd set the node's zPosition property. (The zPosition is not inherited by sub-nodes, so if there are any visible sub-nodes, you'll have to adjust their zPositions also.)The easiest thing to do might be simply to set the zPosition to -position.y. That will make the nodes towards the top of the scene far away, and nodes towards the bottom nearer. Of course, any nodes behind the monsters would then need to have a zPosition farther away than any of them.If you wanted a tighter spread of zPosition, just sort the monsters by position.y and give the monster at index i a zPosition of monsters.count - i. (You can multiply by 5 or something if you want each monster to have a range of zPositions so that subnodes can be displayed properly relative to each other.)
Topic: Graphics & Games SubTopic: SpriteKit Tags:
Aug ’15
Generic constraints with non-protocol types
It would be great if we could write generic constraints which are expressed in terms of other generic constraints. It would allow us to create much more powerful constructs with greater expressiveness to the type-system.One example which would be helpful:enum Either<T1,T2> { case A( T1 ) case B( T2 ) func asCommonType<T where T1:T, T2:T>( type: T.Type ) -> T { switch self { case .A( let val ): return val as! T case .B( let val ): return val as! T } } }Then I could use the Either type like this:let someView : Either<UIButton, UIImageView> ... view.addSubview( someView.asCommonType( UIView.Type ) )With compile-time guarantees which restrict the types that someView may be assigned, and also when it is used that it may be represented as a UIView. If anybody changes the code in a way which violates this relationship, it won't compile.Currently this isn't possible, as the compiler complains on line 06 that T isn't a protocol type. I can't represent this type relationship stati
Replies
6
Boosts
0
Views
8.3k
Activity
Jul ’15
Core Data & iCloud Error: Unable to find relationship destination object
Stackoverflow link: http://stackoverflow.com/questions/31695187/core-data-icloud-error-unable-to-find-relationship-destination-objectI´ve been using Core Data and iCloud for a while in my app now. But its suddenly acting up like crazy. The problem is when a device should import new changes from iCloud i.e in the- (void)persistentStoreDidImportUbiquitousContentChanges:(NSNotification *)notificationIf I add 1 new entity on device A the entity will sync over to device B. But if I add multiple new entities at the same time only the one or two last will sync over to device B. This is when I get the error message:Unable to find relationship destination object: [_PFUbiquityRecordImportOperation processObjects:withState:andImportContext:outError:](1017): CoreData: Ubiquity: <_PFUbiquityRecordImportOperation: 0x14694540>{name = '(null)'}I am also printing whats about to change (the [notification userInfo]) and it looks like this when following that error message.{ deleted = {(n)}; inserted = {(
Replies
0
Boosts
0
Views
402
Activity
Jul ’15
Reply to Generic constraints with non-protocol types
That's really not a solution to anything, and the whole idea of adding junk dummy protocols around your project just to work around the type system is really abhorrent to me.That dummy protocol is a guarantee of nothing. Anybody could add comformance to that protocol, and then totally defeat the type constraints I've built in to my components. I would need to flesh out that protocol with the specific methods I need (like removeFromSuperview), and I'd need to write shims for every method I need which accepts a concrete type and relies on inheritance for specialisation. Essentially, I would need to rewrite UIView as a protocol. And even then it would be horribly unsafe - somebody could just go ahead and write:extension String : ViewMaster {}and then they'd defeat all of your type guarantees and lose all of the information that those type constraints give.In this case, you might know never to make String conform to ViewMaster. In other cases, you might not be aware of all of the implications of that con
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to Generic constraints with non-protocol types
junk dummy protocols are actually known as marker protocols. They won't be necessary when Swift allows us to extend existing type with attributes.I don't know what you mean by this:Anybody could add comformance to that protocol, and then totally defeat the type constraints I've built in to my components. I would need to flesh out that protocol with the specific methods I need (like removeFromSuperview), and I'd need to write shims for every method I need which accepts a concrete type and relies on inheritance for specialisation.No programming language yet provides the amount of static analysis necessary for everyone's needs.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’15
Reply to How do we write type specific extensions to Array?
You can constrain it to your own protocol type, but if you want to append you (as noted by OOPer) have to create the right type to append. Unless your protocol includes an init or some other method that returns Self there is no way for you to do that. IntegerType DOES have such a method: it inherits from IntegerLiteralConvertible, so the integer literals you were appending could be constructed as the correct type depending on whether, for example, the array was [Int] or [UInt8] or whatever.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’15
Remove recently added view
Hi,I have a tabbarcontroller based app. In one tab, there is a navigationcontroller and various view controllers that get pushed onto it via storyboard segues.I'm attempting to create a semi-transparent overlay for help instructions. The plan was to make a detached UIViewController with an UIImageView (the help text and arrows) and a button to dismiss it. This help/tutorial view would be created in the first view controller (the normal UI for the user if they do not want help overlays) which is connected to the navigation controller via a relationship segue. The tutorial view is then added as a subview.I can get the overlay portion working and the button receives the taps well enough. It's removing the view in favor of the old view which is problematic.Here is the code in the regular UI view controller that creates the controller for the tutorial overlay and then adds its view:TutorialsAddItemsViewController* tv = [self.storyboard instantiateViewControllerWithIdentifier:@tutorial]; [self.navigationCo
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
5
Boosts
0
Views
2.9k
Activity
Aug ’15
Reply to Compiler crash with protocol extension
I have tried this:extension Optional: HashValue where T: Hashable { func hashValue() -> Int { switch self { case let .Some(t): return t.hashValue case .None: return 1 } } }But that gives the error:Extension of type 'Optional' with constraints cannot have an inheritance clauseDid you have something else in mind.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’15
Recursive entities
I have a Bracket entity that contains some number of Match entities, so that's a simple 1 to many relationship. On Match though, I now want to point to the next winner match and the next loser match, plus a couple other options (I have 4 destination matches). How do I do that and still handle the fact Core Data wants pointers to the source entity.
Replies
1
Boosts
0
Views
181
Activity
Aug ’15
predicate search on array with Core date Entity with NSDates for just a given calendar unit in date.
i have an array of entities with date objects in relationship end. I know how to filter out objects for given dates or date ranges using predicates. my situation is that now i need to filter out objects matching a given value of a calendar unit. like year 2001 or month 4.now for year this seems simple cause i can just make a start date and end date with jan 1 and dec 31 for given year. but for month week this is an impossible task to calulate start and end dates of each week or even months as there are leap years. there has to be a simpler way where i can just mention in the predicate as to which date component i want to be matched. please let me know how to do it.thanks.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
8
Boosts
0
Views
1.8k
Activity
Aug ’15
Reply to App Store icon on lockscreen
In the old version of the forums, a user posted the answer they got from Developer Support:https://devforums.apple.com/message/1067418#1067418 Location relevant Apps are recommended on the lock screen and in the App Store based on a number of factors, including their popularity at the location, and there is no mechanism or process by which an App developer can add their App to the list of recommended Apps. However, if your iOS App is directly related to the location or venue (such as a mall guide iOS App which is published by the mall owner or operator), and you believe your iOS App’s relevance warrants it being included the list of recommended Apps, then you are encouraged to submit an enhancement request via http://bugreport.apple.com/, and request that Apple consider whether your iOS App should be included in the list of recommended Apps for that location. You should provide as much detail in the ’enhancement request' about the App and venue/location as possible, such as the App ID, App Name, URL to the Ap
Replies
Boosts
Views
Activity
Aug ’15
Reply to predicate search on array with Core date Entity with NSDates for just a given calendar unit in date.
To be honest I stay away from blocks as I don't understand them fully.over here what should be my arguments to the block if the entity i am evaulating is A and the relation object is Date.date. so basically i want all A who have relationship Date's attribute date having year 1998 (for example)
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Aug ’15
Protocol extension to bridge static and dynamic type worlds
I can write global functions to evaluate hashValues, e.g.:func hashValueHashable<T: Hashable>(h: T) -> Int { // Pointless because of static dispatching! return h.hashValue } func hashValueNonHashable(a: Any) -> Int { if let a = a as? AnyObject { return ObjectIdentifier(a).hashValue } return 0 }But this isn't very satisfactory because I need to manually specify which version, i.e. no dynamic dispatch.Therefore I tried to work out how to do something similar using extensions. My 1st try was extending `Any`:extension Any: Hashable { // Error: Non-nominal type `Any` cannot be extended var hashValue: Int { if let self = self as AnyObject { return ObjectIdentifier(self).hashValue } return 0 } }No luck. How about `AnyObject`?extension AnyObject: Hashable { // Error: `AnyObject` protocol cannot be extended var hashValue: Int { return ObjectIdentifier(self).hashValue } }No luck again. How about `Hashable`?extension Hashable where Self: AnyObject { var hashValue: Int { return ObjectIdentifier(self).hashValu
Replies
1
Boosts
0
Views
1.3k
Activity
Aug ’15
Reply to Recursive entities
You do exactly what you'd do in any other case:Create a new relationship on Match, and specify that the type is Match.Naturally, you'll want to specify that the relationship is optional (since not every Match will have a next winner match or a next loser match).If tracking the inverse of the four different destination matches is inconvenient, don't specify an inverse for those relationships.
Replies
Boosts
Views
Activity
Aug ’15
Reply to Protocol Oriented Programming boilerplate code
I think there's more going on here than you think.What you're really asking for is inheritance, which currently does not exist for value types. Protocol extensions are vaguely similar to inheritance in some ways, but not currently so far as to allow you to have default stored properties.You could use inheritance if your columns were classes instead of structs. Indeed, in this case, I think it's clear that your columns should be classes instead of structs. Generally, structs are inappropriate when their value represents the state of some thing, whether it's a real world object or a specific entity like a column (presumable of some table or list). In this case, a particular column has one true name, presumably along with other one true properties that you haven't shown us. If the column's one true state is immutable, it doesn't really matter whether it's a value type or a reference type, but if it's mutable as yours seems likely to be, then it's almost certainly better to use a refere
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’15
Reply to Ordering z-values of all objects in a layer, help!
I assume you have a way to get to the SKSpriteNode for each monster. To adjust the z-value, you'd set the node's zPosition property. (The zPosition is not inherited by sub-nodes, so if there are any visible sub-nodes, you'll have to adjust their zPositions also.)The easiest thing to do might be simply to set the zPosition to -position.y. That will make the nodes towards the top of the scene far away, and nodes towards the bottom nearer. Of course, any nodes behind the monsters would then need to have a zPosition farther away than any of them.If you wanted a tighter spread of zPosition, just sort the monsters by position.y and give the monster at index i a zPosition of monsters.count - i. (You can multiply by 5 or something if you want each monster to have a range of zPositions so that subnodes can be displayed properly relative to each other.)
Topic: Graphics & Games SubTopic: SpriteKit Tags:
Replies
Boosts
Views
Activity
Aug ’15