• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to do isKindOfClass in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to do isKindOfClass in Swift


  • Subject: Re: How to do isKindOfClass in Swift
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Mon, 12 Sep 2016 15:32:45 +0700

> On 12 Sep 2016, at 15:10, Quincey Morris <email@hidden> wrote:
>
> On Sep 12, 2016, at 01:00 , Gerriet M. Denkmann <email@hidden> wrote:
>>
>> This is what I wanted to write:
>>
>> if self is SArray { … }
>> But the compiler warns me: Cast from ‘SBase.Type’ to unrelated type 'SArray' always fails.
>> It is right: the test always fails. And wrong: they are NOT unrelated: SArray is subclass of SBase.
>
> I typed this into a playground:
>
>> class SBase {
>> 	func a () 	{
>> 		if self is SArray { print ("SArray") } else { print ("not SArray") }
>> 	}
>> }
>>
>> class SArray: SBase {
>> }
>>
>> let s1 = SBase ()
>> s1.a ()
>> let s2 = SArray ()
>> s2.a ()
>
> and got this output:
>
>> not SArray
>> SArray
>
> So you’re doing something different. Can you show a code fragment that demonstrates the problem in a playground?

I tried it in a playground and got exactly the same results as you.

I seem to remember that in the last WWDC videos there was some mention that Swift 3 would do module-wide optimisation.
If this is correct, then this might imply that Swift 2.x cannot do this.

In my real (as opposed to playground) code, each class lives in a different file.
So maybe this makes the Swift 2.x compiler think that these classes are unrelated.

By the way: was there is the last keynote a mention of the time for macOS 12?

Kind regards,

Gerriet.


_______________________________________________

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


  • Follow-Ups:
    • Re: How to do isKindOfClass in Swift
      • From: Quincey Morris <email@hidden>
References: 
 >How to do isKindOfClass in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: How to do isKindOfClass in Swift (From: Quincey Morris <email@hidden>)
 >Re: How to do isKindOfClass in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: How to do isKindOfClass in Swift (From: Quincey Morris <email@hidden>)
 >Re: How to do isKindOfClass in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: How to do isKindOfClass in Swift (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: How to do isKindOfClass in Swift
  • Next by Date: Re: How to do isKindOfClass in Swift
  • Previous by thread: Re: How to do isKindOfClass in Swift
  • Next by thread: Re: How to do isKindOfClass in Swift
  • Index(es):
    • Date
    • Thread