how to do it on objective-c: extending protocol and interface like in java

孤街醉人 提交于 2019-12-11 09:48:44

问题


I have this in java:

public interface SomeInterface {
    public void doSomething();
}

public class ParentClass {
}

public class ChildClass extends ParentClass implements SomeInterface {
    public void doSomething() { }
}

Is this possible on objective c? How to do it on objective-c?


回答1:


It sounds like you're just asking "How do I declare that a class conforms to a protocol?" If that's what you're asking, Cocoa is full of examples. Here's the declaration of NSString:

@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>

You would probably benefit from reading Apple's overview, The Objective-C Programming Language. It's short and covers pretty much everything you need to know about the Objective-C language itself.




回答2:


As long you have this method public void doSomething() defined in ChildClass it is fine.



来源:https://stackoverflow.com/questions/2284569/how-to-do-it-on-objective-c-extending-protocol-and-interface-like-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!