我想知道 Objective-C 中的@interface 是什么?它只是程序员想要声明变量、类名或方法名的地方吗……?我不确定它是否像 Java 中的接口(interface)。 还有关于 Objective-C 中的@protocol。看起来更像是Java中的接口(interface)。 谁能给我详细的解释。我真的很感激。
最佳答案
接口(interface)是定义类的属性和操作的地方。你也必须制定实现。
协议(protocol)就像java的接口(interface)。
例如
@protocol Printing
-(void) print;
@end
可以实现
通过声明(在界面中混淆)
@interface Fraction: NSObject <Printing, NSCopying> {
//etc..
对于 java 开发人员来说,令人困惑的是花括号 {}
不是接口(interface)的结尾,例如
@interface Forwarder : Object
{
id recipient;
} //This is not the end of the interface - just the operations
- (id) recipient;
- (id) setRecipient:(id) _recipient;
//these are attributes.
@end
//This is the end of the interface
关于objective-c - @interface 和 @protocol 解释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1679145/