I need to do things differently in the shared delegate based on the controller type, so this probably won’t work. But thanks, I believe it will come in handy when I do need to branch on controllers themselves.
I do have a question though, since the method is a callback, and its signature is changed (with "Thing &” added), will NSFetchedResultsController be able to find it and call it?
···
On 8 Oct 2017, at 12:14 AM, C. Keith Ray <keithray@mac.com> wrote:
Or make a base class for both Controller classes which defines todo () and override todo() in each Controller class.
On Oct 7, 2017, at 9:12 AM, C. Keith Ray <keithray@mac.com <mailto:keithray@mac.com>> wrote:
You should be able to do this to avoid casting.(I think)
protocol Thing {
func todo()
}
class Controller1: NSFetchedResultsController<NSManagedObject>, Thing {
func todo () {doOneThing}
}
class Controller2: NSFetchedResultsController<NSManagedObject>, Thing {
func todo () {doAnotherThing}
}
Oh I see. I think the problem is that with Objective-C generics, you can always cast from Foo<A> to Foo<B>, because the type parameters do not really exist. Swift’s type checking logic for casts assumes Swift generic semantics, where in general Foo<A> and Foo<B> are unrelated types.
Do you mind filing a bug?
Slava
···
On Oct 6, 2017, at 11:40 PM, Glen Huang <heyhgl@gmail.com> wrote:
NSFetchedResultsController is the class from Core Data:
In the mean time, is there any workaround? Or it’s not possible to check the concrete type without this issue being fixed?
···
On 7 Oct 2017, at 2:44 PM, Slava Pestov <spestov@apple.com> wrote:
Oh I see. I think the problem is that with Objective-C generics, you can always cast from Foo<A> to Foo<B>, because the type parameters do not really exist. Swift’s type checking logic for casts assumes Swift generic semantics, where in general Foo<A> and Foo<B> are unrelated types.
Do you mind filing a bug?
Slava
On Oct 6, 2017, at 11:40 PM, Glen Huang <heyhgl@gmail.com> wrote:
NSFetchedResultsController is the class from Core Data:
On Oct 7, 2017, at 10:32 PM, Glen Huang <heyhgl@gmail.com> wrote:
I need to do things differently in the shared delegate based on the controller type, so this probably won’t work. But thanks, I believe it will come in handy when I do need to branch on controllers themselves.
I do have a question though, since the method is a callback, and its signature is changed (with "Thing &” added), will NSFetchedResultsController be able to find it and call it?
On 8 Oct 2017, at 12:14 AM, C. Keith Ray <keithray@mac.com <mailto:keithray@mac.com>> wrote:
Or make a base class for both Controller classes which defines todo () and override todo() in each Controller class.
On Oct 7, 2017, at 9:12 AM, C. Keith Ray <keithray@mac.com <mailto:keithray@mac.com>> wrote:
You should be able to do this to avoid casting.(I think)
protocol Thing {
func todo()
}
class Controller1: NSFetchedResultsController<NSManagedObject>, Thing {
func todo () {doOneThing}
}
class Controller2: NSFetchedResultsController<NSManagedObject>, Thing {
func todo () {doAnotherThing}
}
You can try upcasting the value to NSObject first, and then performing a conditional downcast to Controller1 and Controller2. At this point the type checker will not have enough information to decide that the cast always fails, and should no longer emit a warning.
Slava
···
On Oct 6, 2017, at 11:55 PM, Glen Huang <heyhgl@gmail.com> wrote:
In the mean time, is there any workaround? Or it’s not possible to check the concrete type without this issue being fixed?
On 7 Oct 2017, at 2:44 PM, Slava Pestov <spestov@apple.com <mailto:spestov@apple.com>> wrote:
Oh I see. I think the problem is that with Objective-C generics, you can always cast from Foo<A> to Foo<B>, because the type parameters do not really exist. Swift’s type checking logic for casts assumes Swift generic semantics, where in general Foo<A> and Foo<B> are unrelated types.
Do you mind filing a bug?
Slava
On Oct 6, 2017, at 11:40 PM, Glen Huang <heyhgl@gmail.com <mailto:heyhgl@gmail.com>> wrote:
NSFetchedResultsController is the class from Core Data:
On 7 Oct 2017, at 2:56 PM, Slava Pestov <spestov@apple.com> wrote:
You can try upcasting the value to NSObject first, and then performing a conditional downcast to Controller1 and Controller2. At this point the type checker will not have enough information to decide that the cast always fails, and should no longer emit a warning.
Slava
On Oct 6, 2017, at 11:55 PM, Glen Huang <heyhgl@gmail.com <mailto:heyhgl@gmail.com>> wrote:
In the mean time, is there any workaround? Or it’s not possible to check the concrete type without this issue being fixed?
On 7 Oct 2017, at 2:44 PM, Slava Pestov <spestov@apple.com <mailto:spestov@apple.com>> wrote:
Oh I see. I think the problem is that with Objective-C generics, you can always cast from Foo<A> to Foo<B>, because the type parameters do not really exist. Swift’s type checking logic for casts assumes Swift generic semantics, where in general Foo<A> and Foo<B> are unrelated types.
Do you mind filing a bug?
Slava
On Oct 6, 2017, at 11:40 PM, Glen Huang <heyhgl@gmail.com <mailto:heyhgl@gmail.com>> wrote:
NSFetchedResultsController is the class from Core Data: