Swift -> Obj-C: return __kindof Something
Swift -> Obj-C: return __kindof Something
- Subject: Swift -> Obj-C: return __kindof Something
- From: Steve Christensen via Cocoa-dev <email@hidden>
- Date: Mon, 11 Nov 2019 15:07:40 -0800
I’m working on an Obj-C app that got started a bunch of years ago and thought
that I would start migrating some of the smaller pieces over to Swift.
Some existing Obj-C methods are of the form:
+ (nullable __kindof NSManagedObject) someFooThing;
Right now I have
class var someFooThing: NSManagedObject?
but that generates a bunch of warnings saying there are incompatible pointer
type, so Obj-C callers will need to cast the result to the specific subclass
type:
SonOfFoo sonOfFoo = (SonOfFoo)SonOfFoo.someFooThing;
which was what the original method handled automagically.
I tried the generics route but Xcode complains because it will be used in
Obj-C. Obviously I can just go through and cast to clean up the warnings, but
if there’s a nicer solution then I’d rather go that route.
I’ve been searching around this afternoon trying to see if anyone else has run
across this. I haven’t found anything yet, but I don’t know if that’s due to
poor search terms, or because someone more experienced with the process would
say, “well, of course you can’t do that”. Any help?
Thanks,
Steve
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden