Re: Swift -> Obj-C: return __kindof Something

2019-11-11 Thread Quincey Morris via Cocoa-dev
There’s now a Swift equivalent (loosely): “some NSManagedObject”. It’s 
sometimes referred to as a “reverse generic”, or “opaque type” because it hides 
the actual type behind a larger class type or protocol. The evolution proposal 
is here, if you want all the gory details:


https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md
 


The problem is, it was designed mainly for return types, and I’m not sure it’s 
entirely easy to use for a stored property. On top of that, it may not work 
with an optional base type.

Still, it might be worth looking into. Again, ask on the Swift forum for 
guidance. You’ll get good answers.

> On Nov 11, 2019, at 18:06 , Steve Christensen  wrote:
> 
> I’m trying to get the same class-or-subclass behavior during compilation.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Swift -> Obj-C: return __kindof Something

2019-11-11 Thread Alex Zavatone via Cocoa-dev
You should be able to look at the header in Swift for your Objective-C class 
and see what it should be.

> On Nov 11, 2019, at 8:06 PM, Steve Christensen via Cocoa-dev 
>  wrote:
> 
> Yep, I understand what it does. I’m trying to get the same class-or-subclass 
> behavior during compilation. I’d looked at the stack overflow article 
> earlier, so I’ll check out the Swift forum to see what’s there. Thanks.
> 
>> On Nov 11, 2019, at 4:43 PM, Quincey Morris 
>>  wrote:
>> 
>>> On Nov 11, 2019, at 15:07 , Steve Christensen via Cocoa-dev 
>>> mailto:cocoa-dev@lists.apple.com>> wrote:
>>> 
>>> Some existing Obj-C methods are of the form:
>>> 
>>> + (nullable __kindof NSManagedObject) someFooThing;
>>> 
>>> Right now I have
>>> 
>>> class var someFooThing: NSManagedObject?
>> 
>> AFAIK, “__kindof” only affects the ability to assign one Obj-C class pointer 
>> to a variable of a different but compatible (kind of) type. It doesn’t 
>> change the actual type of the variable, nor does it (again AFAIK) change the 
>> ability to assign without errors in Swift. Also see here for some 
>> informative discussion:
>> 
>>  https://stackoverflow.com/questions/31399208/ios-kindof-nsarray 
>> 
>> 
>> I suggest you ask about this on forums.swift.org . 
>> If there’s an alternative, someone there will know.
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Swift -> Obj-C: return __kindof Something

2019-11-11 Thread Steve Christensen via Cocoa-dev
Yep, I understand what it does. I’m trying to get the same class-or-subclass 
behavior during compilation. I’d looked at the stack overflow article earlier, 
so I’ll check out the Swift forum to see what’s there. Thanks.

> On Nov 11, 2019, at 4:43 PM, Quincey Morris 
>  wrote:
> 
>> On Nov 11, 2019, at 15:07 , Steve Christensen via Cocoa-dev 
>> mailto:cocoa-dev@lists.apple.com>> wrote:
>> 
>> Some existing Obj-C methods are of the form:
>> 
>>  + (nullable __kindof NSManagedObject) someFooThing;
>> 
>> Right now I have
>> 
>>  class var someFooThing: NSManagedObject?
> 
> AFAIK, “__kindof” only affects the ability to assign one Obj-C class pointer 
> to a variable of a different but compatible (kind of) type. It doesn’t change 
> the actual type of the variable, nor does it (again AFAIK) change the ability 
> to assign without errors in Swift. Also see here for some informative 
> discussion:
> 
>   https://stackoverflow.com/questions/31399208/ios-kindof-nsarray 
> 
> 
> I suggest you ask about this on forums.swift.org . 
> If there’s an alternative, someone there will know.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Swift -> Obj-C: return __kindof Something

2019-11-11 Thread Quincey Morris via Cocoa-dev
> On Nov 11, 2019, at 15:07 , Steve Christensen via Cocoa-dev 
>  wrote:
> 
> Some existing Obj-C methods are of the form:
> 
>   + (nullable __kindof NSManagedObject) someFooThing;
> 
> Right now I have
> 
>   class var someFooThing: NSManagedObject?

AFAIK, “__kindof” only affects the ability to assign one Obj-C class pointer to 
a variable of a different but compatible (kind of) type. It doesn’t change the 
actual type of the variable, nor does it (again AFAIK) change the ability to 
assign without errors in Swift. Also see here for some informative discussion:

https://stackoverflow.com/questions/31399208/ios-kindof-nsarray 


I suggest you ask about this on forums.swift.org . If 
there’s an alternative, someone there will know.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Swift -> Obj-C: return __kindof Something

2019-11-11 Thread Steve Christensen via Cocoa-dev
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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com