Question

I'm trying to overwrite the initWithFileURL of an UIDocument as I need to call some custom methods once an UIDocument is initialised.

I thought this may be a good idea:

-(id)initWithFileURL:(NSURL *)url {
        self = [super initWithFileURL:url];
        // do some custom stuff
        return self;
}

Is there anything else I need to do if I overwrite this? I have the feeling that I need to check for NIL or something. Where do you usually look if you need to overwrite a method with something custom? I was only able (via jump to definition when right clicking UIDocument) to see this:

    #pragma mark *** Initialization ***

// The designated initializer. Passing an empty URL will cause this method to throw an NSInvalidArgumentException.
- (id)initWithFileURL:(NSURL *)url;
Was it helpful?

Solution

You should probably be doing this.

-(id)initWithFileURL:(NSURL *)url {
    self = [super initWithFileURL:url];

    if(self) {

      // Your custom stuff here

   }

    return self;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top