开发者

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

开发者 https://www.devze.com 2022-12-20 07:00 出处:网络
I have this in java: public interface SomeInterface { public void doSomething(); } public class ParentClass {

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消