@interface和@protocol解释? [英] @interface and @protocol explanation?

查看:226
本文介绍了@interface和@protocol解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道目标C中的@interface是什么?程序员只是想在其中声明变量,类名或方法名...吗?我不确定它是否类似于Java中的接口. 关于目标C中的@protocol也是如此.似乎Java中的接口更多. 谁能给我详细的解释.我真的很感激.

I would like to know what the @interface in objective C is? is it just where the programmer want to declare the variables, class name or method names...? I am not sure whether it is like interface in Java. And about the @protocol in objective C as well. It seems like the interface in Java more. Could anyone give me detail explanation please. I truly appreciate it.

推荐答案

接口是您定义类的属性和操作的地方.您还必须列出实现方式.

An interface is where you define the attributes and operations of class. You must set out the implementation too.

协议类似于Java的接口.

A protocol is like an interface for java.

例如

@protocol Printing
    -(void) print;
@end

可以实现

通过声明(在界面中令人困惑)

by declaring (confusingly in the interface)

@interface Fraction: NSObject <Printing, NSCopying> {
//etc..

对于Java开发人员而言,令人困惑的是大括号{}并不是接口的结尾,例如

The confusing thing for java developers is that the curly braces {} are not the end of the interface e.g.

@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

这篇关于@interface和@protocol解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆