Using Super in an Objective C Category?

后端 未结 3 1393
名媛妹妹
名媛妹妹 2020-12-05 02:44

I\'d like to override a method in an Objective C class that I don\'t have the source to.

I\'ve looked into it, and it appears that Categories should allow me to do t

3条回答
  •  误落风尘
    2020-12-05 03:23

    If you will be coding against this class, simply rename the selector to something your code can use, and call the original selector on self:

    @implementation SampleClass (filePathResolver)
    -(NSString*) myFullPathFromRelativePath:(NSString*) relPath
    {
        NSString *result = [self fullPathFromRelativePath: relPath];
    
      ... do some stuff with the old result
    
        return result;
    }
    

    If you want to override the default implementation of this selector for that class, you'll need to use the method swizzling approach.

提交回复
热议问题