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'问题, 类似的如图 已经困扰了好长时间, ...
随机推荐
- poj 1979 走多少个‘ . '问题 dfs算法
题意:给你一个迷宫地图,让你走.问最多可以走多少个“." 思路:dfs 找到起点,然后对起点进行dfs操作. dfs操作时,要把当前的位置标志成"#"表示已经走过,然后进 ...
- Mysql源码编译安装&主从复制
一)camke源码编译安装mysql 1)创建软件安装目录software [root@master software]# ls cmake-2.8.8.tar.gz mysql-5.5.32.tar ...
- Chromium Embedded Framework
关于CEF 近期由于工作需要开始研究了Google的Chromium Embedded Framework(CEF),这是一个基于Google Chromium开源代码的项目,使用CEF可以很方便的在 ...
- luogu2766 最长不下降子序列问题
第一问DP水过.dp[i]代表以i结尾的最长不下降子序列长度. 二三问网络流. 第二问是说每个子序列不能重复使用某个数字. 把每个点拆成p(i),q(i).连边. 要是dp[i]=1,连源,p(i) ...
- luogu2865 [USACO06NOV]路障Roadblocks 次短路
注意:如果是这么个写法,堆数组要开成n+m的. 为什么呢?设想一下从1到2有m条长度递减的路,这岂不是要入队m次-- #include <algorithm> #include <i ...
- Selenium WebDriver-actionchain模拟键盘左键长按
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- Leetcode 482.密钥格式化
密钥格式化 给定一个密钥字符串S,只包含字母,数字以及 '-'(破折号).N 个 '-' 将字符串分成了 N+1 组.给定一个数字 K,重新格式化字符串,除了第一个分组以外,每个分组要包含 K 个字符 ...
- 九度oj 题目1470:调整方阵
题目描述: 输入一个N(N<=10)阶方阵,按照如下方式调整方阵:1.将第一列中最大数所在的行与第一行对调.2.将第二列中从第二行到第N行最大数所在的行与第二行对调. 依此类推...N-1.将第 ...
- 在SAE搭建微信公众账号服务
让我们回到2014年11月,从公司请假回成都,在天府软件园B区旁边的小区里,那个10多平米的出租屋里,闲来无事,我想找个事情做一做,好让我这漂浮的心静下来.大约在半年前就申请了微信的一个公众账号,一直 ...
- ACM程序设计选修课——1043: Radical loves integer sequences(YY)
1043: Radical loves integer sequences Time Limit: 1 Sec Memory Limit: 128 MB Submit: 36 Solved: 4 ...