Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7859097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:46:43+00:00 2026-06-02T21:46:43+00:00

I have a Class reference defined in one of classes working with: Class _objectClass;

  • 0

I have a Class reference defined in one of classes working with:

Class _objectClass;

     if([self.objectClass isSubclassOfClass:[NSManagedObject class]])
        {
           //does not get called
        }

How can I check what kind of Class I’m dealing with?

UPDATE: sorry autocomplete did not show me that isKindOfClass: was available. I’m testing that now

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:46:44+00:00Added an answer on June 2, 2026 at 9:46 pm

    There are two methods you’re interested in:

    isKindOfClass: asks the receiver if it is a class or a subclass, where as isMemberOfClass: asks the receiver if it is the class, but not a subclass. For instance, let’s say you have your NSManagedObject subclass called objectClass.

     if([self.objectClass isKindOfClass:[NSManagedObject class]]) {
         // This will return YES
     }
     else if ([self.objectClass isMemberOfClass:[NSManagedObject class]]) {
         // This will return NO
     }
    

    The first statement returns YES (or true, or 1) because objectClass is a subclass of NSManagedObject. The second statement returns NO (or false, or 0) because while it is a subclass, it is not the class itself.

    UPDATE: I’d like to update this answer to bring light to a comment below, which states that this explanation is wrong because the following line of code:

    if ([self.class isKindOfClass:self.class])
    

    would return false. This is correct, it would return false. But this example is wrong. Every class that inherits from NSObject also conforms to the NSObject protocol. Within this protocol is a method called class which “returns the class object for the receiver’s class”. In this case, self.class returns whatever class object self is. However, from the documentation on isKindOfClass: –

    Returns a Boolean value that indicates whether the receiver is an
    instance of given class or an instance of any class that inherits from
    that class.

    thus, sending this message to self.class (which is a class) returns false because it is meant to be sent to an instance of a class, not to a class itself.

    If you change the example to

    if([self isKindOfClass:self.class])
    

    You will get YES (or true, or 1).

    My answer here presumes that self.objectClass is an accessor to an instance named objectClass. Sure, it’s a terrible name for an instance of a class, but the question was not “how do I name instances of classes”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three classes; Classes A and B both reference class C . How
I have two classes, one inherited from the other. When I compile, I get
I have defined two models where each one references the other, like so: class
I have a javascript function (class) that takes a function reference as one paremter.
We have the Class object (an object that reference a Class) so you can
I have a class library (.NET) with a reference to a web service (in
I have a class whose constructor takes a const reference to a string. This
I have a class A which takes a reference of B in its constructor.
I have a class which has a private attribute which is a reference to
the basic idea is that you have some class that has a reference type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.