Reputation: 666
I've overridden the description method of an object I created, quite simple. This object is a subclass of NSMutableURLRequest
.
- (NSString *)description
{
return [[NSString alloc] initWithData:self.HTTPBody encoding:NSUTF8StringEncoding];
}
I also put - (NSString *)description;
in the .h
But it is not called when I NSLog
the object. It is not a NSManagedObject
. Even the debugger won't step into "description" if I only call myObject.description;
. I am calling the method precisely on an instance of my object, not just a NSMutableURLRequest
.
EDIT: I instantiate the object like this:
MYRequest *myRequest = [MYRequest requestWithFilter:myFilter];
NSLog(@"%@", myRequest);
And here is the factory method:
@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;
}
What the heck?
Upvotes: 0
Views: 86
Reputation: 6207
NSMutableURLRequest
or NSURLRequest
classes doesn't have - (NSString *)description
method declared.
You are accessing NSObject
's method - (NSString *)description
.
See this
You should declare your own description
method in your custom class and call it like:
NSString *myObjectDescription = [myCustomObject description];
Upvotes: 0
Reputation: 56099
You don't have an instance of your subclass, you just have a normal NSMutableURLRequest
.
Upvotes: 1