"standard" code ok in simulator but crashes device

Discussion in 'iOS Development' started by cybohemia, May 26, 2009.

  1. cybohemia

    cybohemia New Member

    Joined:
    Jan 25, 2009
    Messages:
    49
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    I have a base class, C, and two derived classes, C1 and C2. I'm using a [self className] in a conditional to see if the object is C1 or C2 and take the appropriate action.

    This works fine in the simulator but, when I compile for the device, I get a warning about how "C may not respond to className" and, when I run the app on the device, it crashes on that line of code.

    Does anyone know if I should do something different on the device for this sort of code?

    Thanks!
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    The frameworks aren't exactly the same. If you're trying to get the name of the class, use [[YourObject class] description]. I use it quite a lot.
  3. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    You could uses [self isKindOfClass:[SomeClass class]];
  4. cybohemia

    cybohemia New Member

    Joined:
    Jan 25, 2009
    Messages:
    49
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
  5. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    I didn't read all you wrote, but if trying to get the name of a class, you can try:

    Code:
    NSStringFromClass([object Class]);

Share This Page