问题
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