---
title: "Block super class method to call sub-class"  
description: "Block super class method to call sub-class"  
author: "Anonymous User"  
published: 2015-11-03  
updated: 2015-11-03  
canonical: https://www.mindstick.com/forum/33563/block-super-class-method-to-call-sub-class  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Block super class method to call sub-class

I have some serious code in my app that make our [apps](https://www.mindstick.com/articles/12842/6-apps-for-writers-that-are-actually-worth-downloading) superclass method dangerous, whenever I run the app it will hang in a loop in the [context](https://www.mindstick.com/forum/23245/what-is-context-in-android) of the subclass. I know it is not a good work but I am a [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) in [app development](https://www.mindstick.com/services/mobile-app-development) so I’ll take time to learn. I our code I need to either [block](https://www.mindstick.com/forum/157599/explain-the-process-control-block-pcb-in-the-operating-system) that method form outside or [throw an exception](https://www.mindstick.com/forum/159239/what-is-the-use-of-the-throw-keyword-to-manually-throw-an-exception-in-java) whenever it is called directly to the superclass, but still I am using it from sub-[class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp), without caring it.\
So, I want the best way to do it.\
Here is the code that created [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) on my app, In sub-class my [override method](https://www.mindstick.com/interview/778/can-you-declare-the-override-method-static-while-the-original-method-is-non-static) 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.\

## Replies

### Reply by Tarun Kumar

To overcome the problem, use this code in your .h file:

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

Using [method](https://www.mindstick.com/forum/166/webservice-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;     }
```


---

Original Source: https://www.mindstick.com/forum/33563/block-super-class-method-to-call-sub-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
