I'm writing a subclass of NSURL
(along with a partnering subclass of NSURLProtocol
). I'm intentionally stashing an additional data property on the URL object intended to be retrieved and used in the URL loading. (This is just an experiment; don't judge.)
However, when I test out the class combo by creating one of these custom URL objects and then trying to load from it...
NSData * data = [NSData dataWithContentsOfURL:myURL];
...my URL protocol gets handed an actual NSURL
instance to inspect, not the instance that I created. Its absoluteString
is what I expect-- in other words, the loading internals have copied my original URL to a new one-- but it's not my custom subclass, so it's missing the extra property.
Note that my NSURL
subclass correctly overrides -copyWithZone:
for NSCopying compliance and both -initWithCoder:
and -encodeWithCoder:
for NSSecureCoding
compliance. This should ensure that anyone making a shallow or deep copy of an instance of my class should get a full, correct copy. But none of these methods are called during this process. (Neither is absoluteString
, path
, relativeString
, etc.)
Someone's "copying" out my URL's (string) contents without calling any of the methods I'd expect to see. I suppose another Foundation class could just be bypassing the public interface and accessing a private/internal property to do this.
Can anyone confirm if NSURL is fundamentally un-subclassable? Or if I might be missing something?