• 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: 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


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

  • Prev by Date: How to do isKindOfClass in Swift
  • Next by Date: Re: Linking against AVKit breaks app on 10.6
  • Previous by thread: How to do isKindOfClass in Swift
  • Next by thread: Re: How to do isKindOfClass in Swift
  • Index(es):
    • Date
    • Thread