Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURL hidden method queryParameters may override category

I have this strange behavior where one of my category methods gets overridden when running on iPhone 3Gs with iOs 5.1.

I have this category:

@interface NSURL (queryParameters)
    - (NSDictionary *) queryParameters;
@end

that returns a dictionary with NSString keys and NSArray values (multiple parameters with same name in my url).

It works fine except on the device mentioned above where I get an NSDictionary with NSString as values instead of the NSArray I was expecting (corresponding to last parameter in my url).

I created an empty project where I constructed a dummy NSURL and figured out that it responds to selector "queryParameters", and returns an NSDictionary with NSString as values:

NSString *urlString = @"http://dummy.url?foo=bar1&foo=bar2";
NSURL *url = [NSURL URLWithString:urlString];

NSLog(@"%@", [url respondsToSelector:@selector(queryParameters)]?@"YES":@"NO");
    // YES

NSLog(@"%@", [[url performSelector:@selector(queryParameters)] debugDescription]);
    // {
    //     foo = bar2;
    // }

So I have 2 questions:

  • Does anybody know if this method belongs to Apple private api (or anything else)?

EDIT: According to this page iOS6-Private-Frameworks, this "queryParameters" is an undocumented method of NSURL (but that doesn't explain why in some case it was overridden).

  • Why is my "own" method being overridden by this "private" method?

Remark: I ended up renaming my own method to avoid this collision.

like image 254
ebany.clio Avatar asked Nov 13 '22 16:11

ebany.clio


1 Answers

I think the convention here is also to prefix your category methods on classes that arent under your control to avoid any name clash!

like image 109
Daij-Djan Avatar answered Nov 15 '22 06:11

Daij-Djan