isKindOf: for two Class objects

  • I have two Class objects and I want to see if one of them isKindOf:
    the other. I started off with this code, but the test always fails:

    Class arrayClass1 = [NSArray class];
    Class arrayClass2 = [NSArray class];

    if ([arrayClass1 isKindOfClass:arrayClass2]) {
      NSLog(@"Success");
    } else {
      NSLog(@"Fail");
    }

    I can see why, since Class's must be their own thing, but I still
    can't figure a good way to do my test. It seems that I need a method
    like instancesRespondToSelector:, except I need
    instancesAreKindOfClass:.

    Any ideas?

    Thanks,
    Jesse
  • On 9/7/07, Jesse Grosjean <jesse...> wrote:
    > I have two Class objects and I want to see if one of them isKindOf:
    > the other. I started off with this code, but the test always fails:
    >
    > Class arrayClass1 = [NSArray class];
    > Class arrayClass2 = [NSArray class];
    >
    > if ([arrayClass1 isKindOfClass:arrayClass2]) {
    > NSLog(@"Success");
    > } else {
    > NSLog(@"Fail");
    > }
    >
    > I can see why, since Class's must be their own thing, but I still
    > can't figure a good way to do my test.

    Is this what you're looking for: [arrayClass1 isSubclassOfClass: arrayClass2]?

    --
    Clark S. Cox III
    <clarkcox3...>
  • >> I have two Class objects and I want to see if one of them isKindOf:
    >> the other. I started off with this code, but the test always fails:
    >>
    >> Class arrayClass1 = [NSArray class];
    >> Class arrayClass2 = [NSArray class];
    >>
    >> if ([arrayClass1 isKindOfClass:arrayClass2]) {
    >> NSLog(@"Success");
    >> } else {
    >> NSLog(@"Fail");
    >> }
    >>
    >> I can see why, since Class's must be their own thing, but I still
    >> can't figure a good way to do my test.
    >
    > Is this what you're looking for: [arrayClass1 isSubclassOfClass:
    > arrayClass2]?

    Yes that does it! Dumb Jesse. Thanks!

    Jesse
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today