문제

I have class containing

.h file.

@interface NewsItem : NSObject
{
NSString* _newsID;
NSString* _newsTitle;
NSString* _imageURL;
NSString* _description;
}
 @property (nonatomic, copy)   NSString* newsID;
 @property (nonatomic, retain) NSString* newsTitle;
 @property (nonatomic, copy)   NSString* imageURL;
 @property (nonatomic, copy)   NSString* description;

.m file

 @implementation NewsItem
 @synthesize newsID= _newsID;
 @synthesize newsTitle= _newsTitle;
 @synthesize imageURL = _imageURL;
 @synthesize description= _description;

Whenever I print the object of newsItem from breakpoint, the value of description field is displayed instead of object reference address. Why so ?

Help Please, Thanks in advance.

도움이 되었습니까?

해결책

You have made the [NSObject description] method a property. Remove _description and @property description and implement the description method yourself:

- (NSString *)description {
    return [NSString stringWithFormat:@"newsID=%@, newsTitle=%@, imageURL=%@", self.newsID, self.newsTitle, self.imageURL];
}

This method will then be called whenever you do the following:

NSLog(@"%@", newsItem);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top