2013-11-22 115 views
2

我有一個自定義對象:Vendor,它的範圍是NSObject。我開始像這樣:創建後自定義對象爲空

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

這裏是一流的樣子:

@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; 
} 

如果我的NSLog vendorObj所有的細節都在那裏。一旦我開始Vendor對象和它的NSLog,日誌顯示:

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

我似乎無法弄清楚,爲什麼我的目標是什麼,沒有的內存地址,甚至沒有空。我在這裏做錯了什麼?

回答

5

問題是您的description屬性。 NSObject類定義了一個description方法。當您將%@格式說明符與對象一起使用時,將調用此方法。您的description屬性重寫該方法。

將您的description屬性重命名爲其他內容。

+0

優秀!我應該看到這一點。非常感謝 – brenjt