Block super class method to call sub-class

Total Post:6

 943  View(s)
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. Post:214

    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;