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 00:27:13 -0700
- Feedback-id: 167118m:167118agrif8a:167118sgTESdW6p0:SMTPCORP
On Sep 12, 2016, at 00:08 , Gerriet M. Denkmann <email@hidden> wrote:
>
> I want to do:
> if self.dynamicType == SomeClass { … }
>
> But the compiler won’t accept this (or any number of variations thereof).
Try this:
if self is SomeClass { … }
Typically, if you need to use a class in an expression, you’ll need to refer to the metatype instance:
if self.dynamicType == SomeClass.self { … }
but this would be an exact match. If you want the semantics of “isKindOf” (that is, the object is of the specified class or a subclass) then “is” is the way to go.
_______________________________________________
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