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'问题, 类似的如图 已经困扰了好长时间, ...
随机推荐
- Hadoop4.2HDFS测试报告之二
第一组:文件存储写过程记录 测试系统组成 存储类型 测试程序或命令 测试文件大小(Mb) 文件个数(个) 客户端并发数(个) 写速率(M/s) NameNode:1 DataNode:1 本地存储 s ...
- Mysql显示某个数据库的所有表
显示表名: show tables; //先用use进入要查看表的库 mysql> use mysql; Database changed mysql> show tables; +--- ...
- No identifier specified for entity: XXXX 错误
在运行项目的时候报了下面的错误: by: org.hibernate.AnnotationException: No identifier specified for entity: com.exam ...
- Mybatis中接口和对应的mapper文件位置配置详解
Mybatis中接口和对应的mapper文件位置配置详解 原链接为:https://blog.csdn.net/fanfanzk1314/article/details/71480954 今天遇到一个 ...
- Leetcode4--->求两个排序数组的中位数
题目:给定两个排序数组,求两个排序数组的中位数,要求时间复杂度为O(log(m+n)) 举例: Example 1: nums1 = [1, 3] nums2 = [2] The median is ...
- 《完美应用Ubuntu》第3版 何晓龙 著
系统篇 用好Ubuntu掌握这些就够了 第1章 Ubuntu的进化 1.1 GNU/Linux的历史和文化 1.1.1 GNU/Linux是Linux的全称 1.1.2 Linux的诞生 1.2 Li ...
- TOJ1698: Balanced Lineup
Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same ...
- 【bzoj1907】树的路径覆盖 树形dp
题目描述 输入 输出 样例输入 1 7 1 2 2 3 2 4 4 6 5 6 6 7 样例输出 3 题解 树形dp 设f[x]表示以x为根的子树完成路径覆盖,且x为某条路径的一端(可以向上延伸)的最 ...
- 【Luogu】P4363一双木棋(状压爆搜)
题目链接 唉,只有AC了这道题才会感叹考场上没有想出解法的我是多么智障. 我甚至连任何想法都没有. 天啊我当时到底在想些什么. AC这道题我就能进前15了诶. 我们发现只要确定了轮廓线那么此时的状态就 ...
- [CODEVS1917] 深海机器人问题(最小费用最大流)
传送门 [问题分析] 最大费用最大流问题. [建模方法] 把网格中每个位置抽象成网络中一个节点,建立附加源S汇T. 1.对于每个顶点i,j为i东边或南边相邻的一个节点,连接节点i与节点j一条容量为1, ...