Re: How to do isKindOfClass in Swift
Re: How to do isKindOfClass in Swift
- Subject: Re: How to do isKindOfClass in Swift
- From: Quincey Morris <email@hidden>
- Date: Mon, 12 Sep 2016 01:10:33 -0700
- Feedback-id: 167118m:167118agrif8a:167118sgTESdW6p0:SMTPCORP
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 am using Swift 3, but this behavior should be the same in Swift 2.)
_______________________________________________
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