BLOCK SUPER CLASS METHOD TO CALL SUB-CLASS

John Brown

Total Post:6

Points:42
Posted by  John Brown
 643  View(s)
Ratings:
Rate this:

I have some serious code in my app that make our apps superclass method dangerous, whenever I run the app it will hang in a loop in the context of the subclass. I know it is not a good work but I am a beginner in app development so I’ll take time to learn. I our code I need to either block that method form outside or throw an exception whenever it is called directly to the superclass, but still I am using it from sub-class, without caring it.
So, I want the best way to do it.
Here is the code that created problem on my app, In sub-class my override method is like this:

- (int) myMethod
{
  [NSException raise:@"HangingProblem!"

format:@"Do not use this method to call directly by the sub-class”];
  return nil;
}

Please give me the suggestions on my code to solve hanging issue.

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Block super class method to call sub-class

    To overcome the problem, use this code in your .h file:

    - (int)dangerousMethod __attribute__((unavailable("message")));

    Using method like above, whenever anyone using your subclass dangerous method will be unavailable,
    To keep other code from using the superclass's version this method, you can further restrict by putting this in your .m file.

    -(int) dangerousMethod{
        return nil;    
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!