ivanzoid/ZZAutoDescription

Crashing

Closed this issue · 6 comments

Given the following class:

typedef NS_ENUM(NSInteger, INFDealerGraphicType)
{
    INFDealerGraphicTypeMap,
    INFDealerGraphicTypePhoto
};


@interface INFDealershipGraphic : NSObject

@property(nonatomic, readonly) INFDealerGraphicType type;
@property(nonatomic, strong, readonly) NSString *resourceName;

+ (instancetype)graphicWithType:(INFDealerGraphicType)type resourceName:(NSString *)resourceName;

- (instancetype)initWithType:(INFDealerGraphicType)type resourceName:(NSString *)resourceName;

- (UIImage *)image;

@end

. . I get a crash on description. Doesn't happen when using AppCode's code-gen'd description.

Perhaps the enum type?

Hi, hm, I've trying pasting the following code:

typedef NS_ENUM(NSInteger, INFDealerGraphicType)
{
    INFDealerGraphicTypeMap,
    INFDealerGraphicTypePhoto
};

@interface INFDealershipGraphic : NSObject

@property(nonatomic, readonly) INFDealerGraphicType type;
@property(nonatomic, strong, readonly) NSString *resourceName;

+ (instancetype)graphicWithType:(INFDealerGraphicType)type resourceName:(NSString *)resourceName;

- (instancetype)initWithType:(INFDealerGraphicType)type resourceName:(NSString *)resourceName;

- (UIImage *)image;

@end

@implementation INFDealershipGraphic

AUTO_DESCRIPTION

+ (instancetype)graphicWithType:(INFDealerGraphicType)type resourceName:(NSString *)resourceName
{
    return nil;
}

- (instancetype)initWithType:(INFDealerGraphicType)type resourceName:(NSString *)resourceName
{
    return nil;
}

- (UIImage *)image
{
    return nil;
}

@end

@implementation ViewController

- (void) viewDidLoad
{
    [super viewDidLoad];

    INFDealershipGraphic *dealershipGraphic = [INFDealershipGraphic new];
    NSLog(@"%@", dealershipGraphic);
}

to the demo project (pod try ZZAutoDescription), and it worked fine.

Please could you tell where exactly it is crashing?
Also could you post contents of implementation of INFDealershipGraphic if it's possible?
It would be the best if we could compose the code which reproducibly crashes.

PS. Also found that [object autoDescription] without AUTO_DESCRIPTION works probably not as expected, need to think how should it behave (at this time it will print results of invoking default NSObject's description method for all objects except standard containers and objects with AUTO_DESCRIPTION).

I'm getting the following (although I have NSZombieEnabled, its not reporting which deallocated object is being messaged):

2014-07-18 07 23 03 pm

Source is simply as follows:

@implementation INFDealershipGraphic

#pragma mark - Class Methods

+ (instancetype)graphicWithType:(INFDealerGraphicType)type resourceName:(NSString *)resourceName
{
    return [[self alloc] initWithType:type resourceName:resourceName];
}

#pragma mark - Initialization & Destruction

- (instancetype)initWithType:(INFDealerGraphicType)type resourceName:(NSString *)resourceName
{
    self = [super init];
    if (self)
    {
        _type = type;
        _resourceName = resourceName;
    }

    return self;
}

#pragma mark - Interface Methods

- (UIImage *)image
{
    return [UIImage imageNamed:_resourceName];
}

- (NSString*)description
{
    return [self autoDescription];
}


@end

Whoops, I didn't examine source attentive and was thinking that bug happens because of the possible issue with feature which tries to avoid possible recursion when printing (when graph of objects to be printed has loops), which I improved just recently, but now I've seen that it is because you only defined description method and didn't define autoDescriptionEnabled. To fix, you may add autoDescriptionEnabled method which returns YES to class, or use AUTO_DESCRIPTION macro.

Thanks. Somehow I missed that from the documentation.

I'm not sure if I asked already but have you thought of adding auto equals and hash code? =

Well, not yet. It would be useful, but I already have a list of things which need to be documented and/or released to cocoapods %)

Suggestion: If user forgets to implement 'autoDescriptionEnabled`, would it be possilbe to crash with a clear error message saying why?