Search results for

“SwiftData inheritance relationship”

4,986 results found

Post

Replies

Boosts

Views

Activity

CoreData can remove object from to many relationship
I've a very strange issue. This happens occasionally when I'm trying to remove an object from a to many relationship.We have 2 objects, a DriverRoute which contains multiple DriverRouteDelivery objects. I try to remove one of the DriverRouteDelivery objects from the DriverRoute, but sometimes the item can't be found in the set even though it's there. I printed the output of lldb. <DriverRoute: 0x812041a0> (entity: DriverRoute; id: 0x7c0ed070 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/DriverRoute/p8> ; data: { changed = 2015-06-22 15:56:28 +0000; createdTimestamp = 2015-06-22 15:36:25 +0000; driver = 0x7f52f080 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/Driver/p1>; id = 4CFA3568-B95E-46D8-A9C7-5EC44BF1ADA8; returnRoute = 0x7bf15e70 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/Route/p23>; routeDeliveries = ( 0x7bf12930 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/DriverRouteDelivery/p24>, 0x7c663b80 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/D
3
0
1.1k
Jun ’15
Reply to Covariant and contravariant generic type parameters
A simple example:extension Comparable { func clampedBetween(minVal: Self, and maxVal: Self) -> Self { return self < minVal ? minVal : self > maxVal ? maxVal : self } }This will give you the ability to do x.clampedBetween(y and z) for x, y, z of any type that conforms to the protocol Comparable (Int, Double, Float, UInt8, ...), and also any new type you make which conforms to Comparable. This will work statically and you will get compile time errors if you try to clamp a value with min and max values of a different type (which is of course a good thing).This would not be possible using inheritance.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’15
Reply to Covariant and contravariant generic type parameters
The problem is not that you can't pass a Dog to that constructor or change the value to a Cat, but that FetchedResults<Dog> is considered a completely different type from FetchedResults<Animal>.You'll see that adding this line to your code won't work:animals = FetchedResults<Dog>(object: Dog())If animals is declared as FetchedResults<Animal>, there is no way to assign it a FetchedResults<Dog> or FetchedResults<Cat>.Variance is about the relationship between the type as a whole and the generic parameter. What covariance means is that these two may covary, so FetchedResults<Dog> would be considered a subtype of FetchedResults<Animal>. This currently happens with arrays and other collection types (so [Dog] is considered a subtype of [Animal]) but is not possible for your own types.This is pretty common in other languages and is something Swift developers have indicated will be available in the future. With lightweight generics in Objective-C it seems there
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’15
Reply to Swift type check like "isMemberOfClass"
I'm assuming you mean for classes that don't inherit from NSObject? There is an is type check operator (see Checking Type in the manual), but it will always return true when checking a superclass:import UIKit class SuperA { } class B: SuperA { } class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let bInstance: SuperA = B() if bInstance is SuperA { // warning: 'is' test is always true print(true) } else { print(false) } } }I'm guessing you already knew about that though, since you say you are asking for something that returns false. Sorry I don't have an answer, but I thought maybe this would clarify your question for others that may read this thread.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’15
Reply to Extension on Generic Type: Bug ?
The generic type Array does not conform to Equatable. This can be further confirmed by eg:extension Array: Equatable {} // Error: Type 'Array' does not conform to protocol 'Equatable'If Array had been Equatable, we would instead have seen the same error message as the one we get for eg String (which is Equatable):extension String: Equatable {} // Error: Redundant conformance of 'String' to protocol 'Equatable'But why does your check work?While something like the following seems to suggest that Array conforms to Equatable:let a = [Hello, world] let b = [Hello, world] print(a == b) // Prints true, but doesn't mean Array is Equatable ...It's not actually the case.If we examine what is actually happening by jumping to the definition of that == in the std lib (ctrl-cmd-J on it), we'll see this:/// Returns true if these arrays contain the same elements. func ==<T : Equatable>(lhs: [T], rhs: [T]) -> BoolNote that the T there is not the Array itself, it's just the Element type of the array type, the arrays a
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’15
Can't scroll up/down and scroll left/right at the same time on UITableView within a UIScrollView
Hi,I'm having trouble implementing custom gesture recognition when multiple gestures are occurring at the same time. I want to have control over which gesture gets picked when the user performs a certain action.I have a couple UITableViews that are within a UIScrollView that has paging enabled, and is setup to let me page left and right so that only one UITableView is visible at a time. A user can't scroll up/down the table view and swipe left/right in the scroll view at the same time, but I would like this to be possible. An example of this would be in the iOS Instagram app on the Activity tab. You can scroll down and then swipe right while the table view is still scrolling.I was able to get the table view to swipe left/right after stopping scrolling up/down by inheriting from UIScrollView and implementing the shouldRecognizeSimultaneouslyWithGestureRecognizer and shouldBeRequiredToFailByGestureRecognizer methods from UIGestureRecognizerDelegate. My idea was to return true in shouldRecognizeSimultan
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
1.4k
Jun ’15
ios9 AddressBookUI display problem and How to build connection with CNContact object and ABRecordRef(or ABRecordID)
Hi, I am a developer of a addressbook(or phonebook) app. I found in ios9 , apple provide the brand new APIs(Contacts and ContactsUI) for reading and writing system address book , which are the replacement of the old AddressBook and AddressBookUI api. I am very happy to use the new api for the convenience, easy for reading and so on.But I found that there are some UI problems When use AddressBookUI in ios9 beta and beta 2 version. The ABNewPersonViewController does not seem good in ios9 (ipod touch 5, iphone 5), when i scroll the ABNewPersionViewController, I found that it(ABNewPersonViewController) can't be scrolled down. So I decide to report this bug.Besides, I have a question about the relationship of Contacts framework and ABAddresBook framework. Are there any connection between a CNContact Object and a ABRecordRef (or ABRecordID)? If it does exist, I want to know how to transfer from a exist(the contact is in the ios system addressbook or contacts) CNContact Object to a ABRecordRef and vice vers
5
0
2.5k
Jun ’15
How to declare a var of specific base class, conforming to a protocol?
How would I declare a variable that is of a specific base class and conforms to a protocol?For example if I haveclass BaseClass { ... } protocol SomeProtocol { ... }I can either declare it asvar someVar: BaseClassor asvar someVar: SomeProtocolbut not asvar someVar: BaseClass, SomeProtocolI also tried to declare the protocol asprotocol SomeProtocol: BaseClassBut of course this didn't work, as non-class types can't inherit from classesIn Objective-C I would doBaseClass<SomeProtocol> *someVar;But in Swift <> is reserved for generics.I can do this for function parameters and it works just as expected:func someFunc<T: BaseClass where T: protocol<SomeProtocol>>(param: T)I could turn my protocol into a subclass of the BaseClass, but what if down the road I need some other base class, conforming to the protocol?My concrete use case is that for a custom keyboard I have a controller that loads a bunch of different UIView subclasses (for different types of keyboards) that are constructed
8
0
2.3k
Jun ’15
Reply to How to declare a var of specific base class, conforming to a protocol?
I could make a class that inherits from UIView (or whatever base class I need) and conforms to the protocol and stub the methods. Then subclass it to my concrete subclasses where I actually implement the methods, but this is a rather messy solution, questioning the role of the protocol.Because I use a protocol exactly because implementation differs in the different subclasses, it's the interface (protocol) that stays the same.For me it is a feature omission. It is something that was there in Obj-C and had it's use cases.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’15
Reply to Covariant and contravariant generic type parameters
Could you explain what the advantage of this is compared to simply use Animal as Superclass and Cat & Dog as Subclasses? This is classic inheritance. What good do generics and protocols bring here? I'm totally confused.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to Covariant and contravariant generic type parameters
I still don't get why use generics here instead of the perfectly fine working inheritance...
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
CoreData can remove object from to many relationship
I've a very strange issue. This happens occasionally when I'm trying to remove an object from a to many relationship.We have 2 objects, a DriverRoute which contains multiple DriverRouteDelivery objects. I try to remove one of the DriverRouteDelivery objects from the DriverRoute, but sometimes the item can't be found in the set even though it's there. I printed the output of lldb. <DriverRoute: 0x812041a0> (entity: DriverRoute; id: 0x7c0ed070 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/DriverRoute/p8> ; data: { changed = 2015-06-22 15:56:28 +0000; createdTimestamp = 2015-06-22 15:36:25 +0000; driver = 0x7f52f080 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/Driver/p1>; id = 4CFA3568-B95E-46D8-A9C7-5EC44BF1ADA8; returnRoute = 0x7bf15e70 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/Route/p23>; routeDeliveries = ( 0x7bf12930 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/DriverRouteDelivery/p24>, 0x7c663b80 <x-coredata://E8AAE873-94B7-42F4-A39A-3A8D7C567747/D
Replies
3
Boosts
0
Views
1.1k
Activity
Jun ’15
Reply to Covariant and contravariant generic type parameters
A simple example:extension Comparable { func clampedBetween(minVal: Self, and maxVal: Self) -> Self { return self < minVal ? minVal : self > maxVal ? maxVal : self } }This will give you the ability to do x.clampedBetween(y and z) for x, y, z of any type that conforms to the protocol Comparable (Int, Double, Float, UInt8, ...), and also any new type you make which conforms to Comparable. This will work statically and you will get compile time errors if you try to clamp a value with min and max values of a different type (which is of course a good thing).This would not be possible using inheritance.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to iPhone and iPad both taking longer times to load since iOS update
Try to restore without backup... These problems appears sometimes when inherited data from previous versions are incompatible and/or invalid. Probably, newer versions will fix it doing some data conversion.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to Covariant and contravariant generic type parameters
The problem is not that you can't pass a Dog to that constructor or change the value to a Cat, but that FetchedResults<Dog> is considered a completely different type from FetchedResults<Animal>.You'll see that adding this line to your code won't work:animals = FetchedResults<Dog>(object: Dog())If animals is declared as FetchedResults<Animal>, there is no way to assign it a FetchedResults<Dog> or FetchedResults<Cat>.Variance is about the relationship between the type as a whole and the generic parameter. What covariance means is that these two may covary, so FetchedResults<Dog> would be considered a subtype of FetchedResults<Animal>. This currently happens with arrays and other collection types (so [Dog] is considered a subtype of [Animal]) but is not possible for your own types.This is pretty common in other languages and is something Swift developers have indicated will be available in the future. With lightweight generics in Objective-C it seems there
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to Covariant and contravariant generic type parameters
Well I still don't get what is missing here. Inheritance works perfectly fine. So where comes the need for genereics in here? 😕
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to Swift type check like "isMemberOfClass"
I'm assuming you mean for classes that don't inherit from NSObject? There is an is type check operator (see Checking Type in the manual), but it will always return true when checking a superclass:import UIKit class SuperA { } class B: SuperA { } class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let bInstance: SuperA = B() if bInstance is SuperA { // warning: 'is' test is always true print(true) } else { print(false) } } }I'm guessing you already knew about that though, since you say you are asking for something that returns false. Sorry I don't have an answer, but I thought maybe this would clarify your question for others that may read this thread.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to Extension on Generic Type: Bug ?
The generic type Array does not conform to Equatable. This can be further confirmed by eg:extension Array: Equatable {} // Error: Type 'Array' does not conform to protocol 'Equatable'If Array had been Equatable, we would instead have seen the same error message as the one we get for eg String (which is Equatable):extension String: Equatable {} // Error: Redundant conformance of 'String' to protocol 'Equatable'But why does your check work?While something like the following seems to suggest that Array conforms to Equatable:let a = [Hello, world] let b = [Hello, world] print(a == b) // Prints true, but doesn't mean Array is Equatable ...It's not actually the case.If we examine what is actually happening by jumping to the definition of that == in the std lib (ctrl-cmd-J on it), we'll see this:/// Returns true if these arrays contain the same elements. func ==<T : Equatable>(lhs: [T], rhs: [T]) -> BoolNote that the T there is not the Array itself, it's just the Element type of the array type, the arrays a
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
to-many relationship fault "..." for objectID
I have a one-many relationship between A and B, when add B to A' set, I got the debug log to-many relationship fault for objectID. How to deal with it?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
0
Boosts
0
Views
136
Activity
Jun ’15
Can't scroll up/down and scroll left/right at the same time on UITableView within a UIScrollView
Hi,I'm having trouble implementing custom gesture recognition when multiple gestures are occurring at the same time. I want to have control over which gesture gets picked when the user performs a certain action.I have a couple UITableViews that are within a UIScrollView that has paging enabled, and is setup to let me page left and right so that only one UITableView is visible at a time. A user can't scroll up/down the table view and swipe left/right in the scroll view at the same time, but I would like this to be possible. An example of this would be in the iOS Instagram app on the Activity tab. You can scroll down and then swipe right while the table view is still scrolling.I was able to get the table view to swipe left/right after stopping scrolling up/down by inheriting from UIScrollView and implementing the shouldRecognizeSimultaneouslyWithGestureRecognizer and shouldBeRequiredToFailByGestureRecognizer methods from UIGestureRecognizerDelegate. My idea was to return true in shouldRecognizeSimultan
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
0
Boosts
0
Views
1.4k
Activity
Jun ’15
ios9 AddressBookUI display problem and How to build connection with CNContact object and ABRecordRef(or ABRecordID)
Hi, I am a developer of a addressbook(or phonebook) app. I found in ios9 , apple provide the brand new APIs(Contacts and ContactsUI) for reading and writing system address book , which are the replacement of the old AddressBook and AddressBookUI api. I am very happy to use the new api for the convenience, easy for reading and so on.But I found that there are some UI problems When use AddressBookUI in ios9 beta and beta 2 version. The ABNewPersonViewController does not seem good in ios9 (ipod touch 5, iphone 5), when i scroll the ABNewPersionViewController, I found that it(ABNewPersonViewController) can't be scrolled down. So I decide to report this bug.Besides, I have a question about the relationship of Contacts framework and ABAddresBook framework. Are there any connection between a CNContact Object and a ABRecordRef (or ABRecordID)? If it does exist, I want to know how to transfer from a exist(the contact is in the ios system addressbook or contacts) CNContact Object to a ABRecordRef and vice vers
Replies
5
Boosts
0
Views
2.5k
Activity
Jun ’15
How to declare a var of specific base class, conforming to a protocol?
How would I declare a variable that is of a specific base class and conforms to a protocol?For example if I haveclass BaseClass { ... } protocol SomeProtocol { ... }I can either declare it asvar someVar: BaseClassor asvar someVar: SomeProtocolbut not asvar someVar: BaseClass, SomeProtocolI also tried to declare the protocol asprotocol SomeProtocol: BaseClassBut of course this didn't work, as non-class types can't inherit from classesIn Objective-C I would doBaseClass<SomeProtocol> *someVar;But in Swift <> is reserved for generics.I can do this for function parameters and it works just as expected:func someFunc<T: BaseClass where T: protocol<SomeProtocol>>(param: T)I could turn my protocol into a subclass of the BaseClass, but what if down the road I need some other base class, conforming to the protocol?My concrete use case is that for a custom keyboard I have a controller that loads a bunch of different UIView subclasses (for different types of keyboards) that are constructed
Replies
8
Boosts
0
Views
2.3k
Activity
Jun ’15
Reply to How to declare a var of specific base class, conforming to a protocol?
I could make a class that inherits from UIView (or whatever base class I need) and conforms to the protocol and stub the methods. Then subclass it to my concrete subclasses where I actually implement the methods, but this is a rather messy solution, questioning the role of the protocol.Because I use a protocol exactly because implementation differs in the different subclasses, it's the interface (protocol) that stays the same.For me it is a feature omission. It is something that was there in Obj-C and had it's use cases.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15
Reply to Why can't I make Array<T: Equatable> conform to Equatable?
I think this is just a current limitation of the type system, since there is a rather specific error if you try to do this (Extension of type 'TypeName' with constraints cannot have an inheritance clause). It's definitely a little disappointing. I filed a Radar (#21507148), and I'm sure others have done so as well.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jun ’15