user3250560
user3250560

Reputation: 666

iOS description method not called

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

Answers (2)

damirstuhec
damirstuhec

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

Kevin
Kevin

Reputation: 56099

You don't have an instance of your subclass, you just have a normal NSMutableURLRequest.

Upvotes: 1

Related Questions