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'问题, 类似的如图 已经困扰了好长时间, ...
随机推荐
- HTTP认证之基本认证——Basic(一)
导航 HTTP认证之基本认证--Basic(一) HTTP认证之基本认证--Basic(二) HTTP认证之摘要认证--Digest(一) HTTP认证之摘要认证--Digest(二) 一.概述 Ba ...
- BZOJ 2687: 交与并
答案存在于 1.两个互相包含的区间 2.两个互不包含的区间 决策单调性显然 但是这代码很精妙啊,并不知道这个为什么能这样写 #include<cstdio> #include<alg ...
- day03 set集合,文件操作,字符编码以及函数式编程
嗯哼,第三天了 我们来get 下新技能,集合,个人认为集合就是用来list 比较的,就是把list 转换为set 然后做一些列表的比较啊求差值啊什么的. 先看怎么生成集合: list_s = [1,3 ...
- [linux time命令学习篇] time 统计命令执行的时间
注意: 命令后面一定要有分号; http://codingstandards.iteye.com/blog/798788 用途说明 time命令常用于测量一个命令的运行时间,注意不是用来显示和修改系统 ...
- /mnt/sdcard 是什么东西
关于/mnt/sdcard和sdcard的区别,可以这样理解:其实,安卓系统是从Linux而衍生出来的,而mnt是unix/Linux传统系统下挂载外部设备的专用目录,Linux默认挂载外部设备都会挂 ...
- Tomcat自动发布war包
有两种方法: 1.将项目打成war包,复制到${tomcat.home}\webapps目录下.当tomcat启动时会自动将其解包. 有人说,不能直接将war文件夹直接复制到${tomcat.home ...
- 防止csrf
//防csrf攻击 $csrf_hash = md5(uniqid(rand(), TRUE)); set_cookie("my_csrf_name", $csrf_hash, 0 ...
- 浅谈android反调试之 API判断
反调试:利用Java层API来判断Android程序是否是处于被调试下. 1.直接调用系统的android.os.Debug.isDebuggerConnected()方法 我们进行动态调试的时候,其 ...
- linux下Apache+Svn环境搭建(五)
在搭建之前先准备好如下包,建议去apache官网去下载:http://httpd.apache.org/ apr-1.4.6.tar.gzapr-util-1.4.1.tar.gzhttpd-2.2. ...
- linux下安装firefox
首先检查系统有没有安装:rpm -qa|grep firefox 如果有安装,先删掉rpm -e * firefox不同版本下载:http://liulanmi.com/firefox 具体方法如下: ...