Class definition
Prerequisite Articles
(None)
Related Articles
A class definition is the specification of a class of objects through the use of certain files and syntax. A class definition minimally consists of two parts: a public interface, and a private implementation. You typically split the interface and implementation into two separate files—the header file and the implementation file. By separating the public and private parts of your code, you retain the class interface as an independent entity.
You usually name the interface and implementation files after the class. Because it’s included in other source files, the name of the interface file usually has the .h extension typical of header files. The name of the implementation file has a .m extension, indicating that it contains Objective-C source code. For example, the MyClass class would be declared in MyClass.h and defined in MyClass.m.
Interface
In the interface, you do several things:
You name the class and its superclass.
You may also specify any protocols that your class conforms to (see Protocol).
You specify the class’s instance variables.
You specify the methods and declared properties (see Declared property) that are available for the class.
In the interface file, you first import any required frameworks. (This will often be just Cocoa/Cocoa.h.) You start the declaration of the class interface itself with the compiler directive @interface and finish it with the directive @end.
#import <Cocoa/Cocoa.h> |
@interface MyClass : SuperClass {
|
int integerInstanceVariable; |
} |
+ (void)aClassMethod; |
- (void)anInstanceMethod; |
@end |
Implementation
Whereas you declare a class’s methods in the interface, you define those methods (that is, write the code for implementing them) in the implementation.
In the interface file, you first import any required header files. (Minimally this will be your class’s header file.) You start the implementation of the class with the compiler directive @implementation and finish it with the directive @end.
#import "MyClass.h" |
@implementation MyClass |
+ (void)aClassMethod {
|
printf("This is a class method\n");
|
} |
- (void)anInstanceMethod {
|
printf("This is an instance method\n");
|
printf("The value of integerInstanceVariable is %d\n", integerInstanceVariable);
|
} |
@end |
Definitive Discussion
Class definition的更多相关文章
- foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Table' because 'System.Web.UI.WebControls.Table' does not contain a public definition for 'GetEnumerator'
错误:foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Table' because ' ...
- `UnityEditor.EditorUtility' does not contain a definition for `GetMiniThumbnail'
I got the following errors with Untiy 4.0f7error CS0117: `UnityEditor.EditorUtility' does not contai ...
- 原创: How to build a query based on Definition Updates installed
In SCCM 2012 R2, you can use following class. Use SMS_CombinedDeviceResources.EPAntivirusSignatureLa ...
- Definition of success-成功的定义
"My definition of success is doing what you love. I fell many people do things because they fee ...
- XSD(XML Schema Definition)用法实例介绍以及C#使用xsd文件验证XML格式
XML Schema 语言也称作 XML Schema 定义(XML Schema Definition,XSD),作用是定义 XML 文档的合法构建模块,类似 DTD,但更加强大. 作用有: ①定义 ...
- TFS Build Definition And Auto Deploy
一台build machine上一般只有一个build service[对应一个build controller]来serve一个team project collection,但又workaroun ...
- multiple definition of `err_sys' 《UNIX环境高级编程》
本文地址:http://www.cnblogs.com/yhLinux/p/4079930.html 问题描述: [点击此处直接看解决方案] 在练习<UNIX环境高级编程>APUE程序清单 ...
- Mysql运行SQL文件 错误Incorrect table definition;there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
问题描述 想从服务器上DOWN下数据库.操作:先把数据库转存为SQL文件,然后在本地利用navicate运行SQL文件,出现错误信息: Incorrect table definition;there ...
- Tomcat7.0启动报错:java.lang.illegalargumentexception:taglib definition not consisten with specification version
Tomcat7.0启动报错:java.lang.illegalargumentexception:taglib definition not consisten with specification ...
- 关于解决keil4和mdk共存后51不能使用go to definition Of 'XXXXXX'问题
自己安装keil4和mdk共存后,(我是先安装的keil 后安装的 MDK),在51单片机工程里不能使用go to definition Of 'XXXXXX'问题, 类似的如图 已经困扰了好长时间, ...
随机推荐
- UVa 12299 线段树 单点更新 RMQ with Shifts
因为shift操作中的数不多,所以直接用单点更新模拟一下就好了. 太久不写线段树,手好生啊,不是这错一下就是那错一下. PS:输入写的我有点蛋疼,不知道谁有没有更好的写法. #include < ...
- oracle游标遍历
--创建存储过程 CREATE OR REPLACE PROCEDURE xxxxxxxxxxx_p (--参数IN表示输入参数,OUT表示输入参数,类型可以使用任意Oracle中的合法类型. is_ ...
- Xpath - Xpath定位
selenium 提供的xpath定位方法名为:find_element_by_xpath(xpath表达式) Xpath基本定位语法: / 绝对定位,从根节点选取 // 相对定位,从匹配选择的当前 ...
- VMware Workstation 14 PRO 下安装Ubuntu 16.04 LTS教程
一.准备好安装的VMware Workstation 14 PRO 1.VMware Workstation 14 PRO下载链接:http://rj.baidu.com/soft/detail/13 ...
- acm之图论基础
1.图的定义 图 是一个顶点集合V和一个顶点间关系的集合E组成,记G=(V,E) V:顶点的有限非空集合. E:顶点间关系的有限集合(边集). 存在一个结点v,可能含有多个前驱节点和后继结点. 1顶点 ...
- C语言总结(5)
一.函数的定义: 函数是一个完成特定工作的独立程序模块,包括库函数和自定义函数.例如:scanf(),printf()为库函数,cylinder(),fact()为自定义函数. 函数定义的一般形式: ...
- 洛谷P4364 [九省联考2018]IIIDX 【线段树】
题目 [题目背景] Osu听过没?那是Konano最喜欢的一款音乐游戏,而他的梦想就是有一天自己也能做个独特酷炫的音乐游戏.现在 ,他在世界知名游戏公司KONMAI内工作,离他的梦想也越来越近了.这款 ...
- 添加gitlab远程账号 使用注意事项
gitlab上面使用的密钥有两种,一种是Deploy keys 这种密钥是只读的,添加了之后,相应设备只拥有clone的权限,不被允许进行push操作.(在相应的库里面的设置里面添加) 还有一种是 S ...
- Spring Boot 配置大全
Spring Boot 允许通过外部配置让你在不同的环境使用同一应用程序的代码,简单说就是可以通过配置文件来注入属性或者修改默认的配置. SpringBoot的配置方式有很多,它们的优先级如下所示(优 ...
- hdu 2262 高斯消元求期望
Where is the canteen Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...