Custom Object empty after creation

浪子不回头ぞ 提交于 2019-12-24 01:24:21

问题


I have a custom object: Vendor that extends NSObject. I am initiating it like so:

NSDictionary *vendorObj = [vendors objectAtIndex:i];
Vendor *vendor = [[Vendor alloc] initWithVendorInfo:vendorObj];
NSLog(@"VendorObj: %@", vendorObj);
NSLog(@"Vendor: %@", vendor);

Here is what the class looks like:

@interface Vendor : NSObject

    @property (nonatomic, copy) NSString *name;
    @property (nonatomic, copy) NSString *description;

    - (id)initWithVendorInfo:(NSDictionary *)vendorDetails;

@end

@implementation Vendor

- (id)initWithVendorInfo:(NSDictionary *)vendorDetails
{
    self = [super init];
    if(self)
    {
        _name = [vendorDetails[@"company_name"] copy];
        _description = [vendorDetails[@"description"] copy];
    }
    return self;
}

If I NSLog vendorObj all the details are there. Once I initiate the Vendor object and NSLog it, the log shows:

2013-11-21 22:22:44.769 [48202:a07] Vendor:

I cannot seem to figure out why my object is nothing, no memory address, not even a null. What am I doing wrong here?


回答1:


The problem is your description property. The NSObject class defines a description method. This method is called when you use a %@ format specifier with an object.

Your description property is overriding that method.

Rename your description property to something else.



来源:https://stackoverflow.com/questions/20137682/custom-object-empty-after-creation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!