2013-11-22 3 views
2

사용자 정의 객체가 있습니다. VendorNSObject입니다. 그래서처럼 시작하고있다 : 나는 vendorObj 모든 세부 사항이있는 NSLog 경우생성 후 사용자 정의 객체가 비어 있음

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

:

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

클래스의 모습이다. 나는 Vendor 객체와 NSLog를 시작하면, 로그를 보여줍니다

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

내 객체가 아무것도없고 메모리 주소, 심지어 널없는 이유를 알아낼 수 없습니다. 여기서 내가 뭘 잘못하고 있니?

답변

5

문제는 사용자의 description 속성입니다. NSObject 클래스는 description 메서드를 정의합니다. 이 메서드는 객체에 %@ 형식 지정자를 사용하면 호출됩니다.

description 속성이 해당 메서드를 재정의합니다.

description 속성의 이름을 다른 것으로 바꿉니다.

+0

우수! 나는 그것을보아야 만했다. 정말 고맙습니다 – brenjt