2014-03-05 124 views
0

我已经重写了我创建的对象的描述方法,很简单。该对象是NSMutableURLRequest的子类。iOS描述方法不叫

- (NSString *)description 
{ 
    return [[NSString alloc] initWithData:self.HTTPBody encoding:NSUTF8StringEncoding]; 
} 

我也把- (NSString *)description;在.H

但是,当我NSLog对象那就不叫。它不是NSManagedObject。如果我只打电话给myObject.description;,即使调试器也不会进入“描述”。我正好在我的对象实例上调用方法,而不仅仅是一个NSMutableURLRequest

编辑: 我实例化这样的对象:

MYRequest *myRequest = [MYRequest requestWithFilter:myFilter]; 

NSLog(@"%@", myRequest); 

这里是工厂方法:

@interface MYRequest : NSMutableURLRequest 
+ (instancetype)requestWithFilter:(NSString *)filter; 


@implementation MYRequest 
+ (instancetype)requestWithFilter:(NSString *)filter 
{ 
    // some config 
    MYRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:15]; 
    // some more config 
    return request; 
} 

什么鬼?

+0

''NSMutableURLRequest''或''没有按NSURLRequest''班”没有'' - (NSString *)说明'方法声明。你正在访问''NSObject''的方法'' - (NSString *)description''。见[this](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#jumpTo_7) – damirstuhec

+0

显示实例化对象的代码。 – Jasarien

+1

正如Kevin在他的回答中所说的,你正在实例化一个NSMutableURLRequest,而不是你的子类。 – Jasarien

回答

1

你没有你的子类的实例,你只是有一个正常的NSMutableURLRequest

0

NSMutableURLRequestNSURLRequest类没有- (NSString *)description方法声明。

您正在访问NSObject的方法- (NSString *)description

this

你应该在你的自定义类声明自己description方法,并调用它像:

NSString *myObjectDescription = [myCustomObject description];