Creating an abstract class in Objective-C

前端 未结 21 2657
感情败类
感情败类 2020-11-22 15:44

I\'m originally a Java programmer who now works with Objective-C. I\'d like to create an abstract class, but that doesn\'t appear to be possible in Objective-C. Is this poss

21条回答
  •  一整个雨季
    2020-11-22 16:28

    No, there is no way to create an abstract class in Objective-C.

    You can mock an abstract class - by making the methods/ selectors call doesNotRecognizeSelector: and therefore raise an exception making the class unusable.

    For example:

    - (id)someMethod:(SomeObject*)blah
    {
         [self doesNotRecognizeSelector:_cmd];
         return nil;
    }
    

    You can also do this for init.

提交回复
热议问题