Objective-C 之Extension
Objective-C 之Extension
class extension:类扩展
类扩展与 category 有相似性,但在编译时它只能被添加到已有源代码的一类中(该类扩展和该类同时被编译)。
- 在extension里面只能写定义,不能写实现。
- 通过扩展可以控制默写函数是否堆外界可见。
- 扩展还可以定义属性(@property)
示例程序:
Student.h
#import <Foundation/Foundation.h>
typedef enum : NSUInteger {
Female,
Male,
} Gender;
@interface Student : NSObject
-(void)sayHello;
@property (readonly) Gender gender;
@end
Student.m
#import "Student.h"
#import "Student_Ext.h"
@implementation Student
-(void)sayHello{
NSLog(@"Student say hello");
self.gender = Female;
}
-(void)sayHi{
NSLog(@"Student say Hi");
}
@end
Student_SayHi.h
#import "Student.h"
@interface Student ()
-(void)sayHi;
@property (readwrite)Gender gender;
@end
main.m
#import <Foundation/Foundation.h>
#import "Student.h"
#import "Student_Ext.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Student *s =[[Student alloc] init];
[s sayHello];
[s sayHi];
}
return 0;
}
category和extension
category是用来扩展累的功能的,而extension仅仅扩展定义,没有源代码的话是不能使用扩展的。
参考资料:
自定义现有的类 - Customizing Existing Classes
类扩展(class extension)
Objective-C 之Extension的更多相关文章
- Automake
Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...
- iOS开发——技术精华Swift篇&Swift 2.0和Objective-C2.0混编之第三方框架的使用
swift 语言是苹果公司在2014年的WWDC大会上发布的全新的编程语言.Swift语言继承了C语言以及Objective-C的特性,且克服了C语言的兼容性问题.Swift语言采用安全编程模式,且引 ...
- MD5 algorithm in Objective C
How to calculate the MD5 in objective C ? md5 is available on the iPhone and can be added as an exte ...
- iOS开发核心语言Objective C —— 全部知识点总结
本分享是面向有意向从事iOS开发的伙伴及苹果产品的发烧友,亦或是已经从事了iOS的开发人员,想进一步提升者.假设您对iOS开发有极高的兴趣,能够与我一起探讨iOS开发.一起学习,共同进步.假设您是零基 ...
- Objective -C Categories
Objective -C Categories The dynamic runtime dispatch mechanism employed by Objective-C lets you add ...
- 关于Objective C的私有函数
(1)很多从其他语言(例如C++)转到objective c的初学者,往往会问到一个问题,如何定义类的私有函数?这里的“私有函数”指的是,某个函数只能在类的内部使用,不能在类的外部,或者派生类内部使用 ...
- Latent Representation Learning For Artificial Bandwidth Extension Using A Conditional Variational Auto-Encoder
博客作者:凌逆战 论文地址:https://ieeexplore.ieee.xilesou.top/abstract/document/8683611/ 地址:https://www.cnblogs. ...
- 论文翻译:2018_Artificial Bandwidth Extension with Memory Inclusion using Semi-supervised Stacked Auto-encoders
论文地址:使用半监督堆栈式自动编码器实现包含记忆的人工带宽扩展 作者:Pramod Bachhav, Massimiliano Todisco and Nicholas Evans 博客作者:凌逆战 ...
- Windbg Extension NetExt 使用指南 【2】 ---- NetExt 的基本命令介绍
摘要 : 本章节介绍NetExt常用的命令. 并且对SOS进行一些对比. NetExt的帮助 要想玩好NetExt, 入门就得看帮助. 看NetExt的帮助可以调用!whelp 命令. 这样hi列举出 ...
- Windbg Extension NetExt 使用指南 【1】 ---- NetExt 介绍
摘要 : 在使用WINDBG做debugging的时候,需要一个好的工具帮助进行数据分析. 最常见的extension包括SOS, PSSCOR. NetExt则是另外一种提供了丰富命令功能的deb ...
随机推荐
- pip install staty
ERROR: Complete output from command python setup.py egg_info:ERROR: Traceback (most recent call last ...
- 一百三十二:CMS系统之前端动态获取后台添加的轮播图
先准备几张轮播图 排序顺序改为根据优先级倒序排 前端首页接口 @bp.route('/')def index(): banners = BannerModel.query.order_by(Banne ...
- C++数据结构之排序
一.简单排序 冒泡排序: 插入排序: 逆序对 希尔排序:
- python使用socket向客户端发送数据的方法
在使用locust测试长连接的时候,所有的请求全部faillure了,所以想到手动写一个连接脚本测试一下是否能连通 因为centos7自带python2.7所以用python写一个比较方便. #!/u ...
- 解决升Win10系统后VMware虚拟机不能联网的问题
刚升级到Win10系统,打开虚拟机发现不能联网,其实是系统服务项里缺少两个用到的服务,不能联网了,下面教大家解决联网问题. 1.打开VMware虚拟机主页,点击“编辑——虚拟网络编辑器”. 2.点击左 ...
- 01.02 linux命令(1
=================常用的Linux命令============================Ls 查看当前文件夹下或者其他文件夹的文件列表或者文件夹列表Ls -l 详细信息的列表L ...
- 周一不睡觉,也要把pandas groupy 肝完,你该这么学,No.8
如果图片无法观看,请移步 https://blog.csdn.net/hihell 学编程就跟打游戏一样一样的 为啥一样啊,因为要肝的 你看,学编程有很多好处 掉头发,有借口吧 不洗头,有借口吧 不洗 ...
- [mysql] C++操作mysql方法
下载:http://mirrors.sohu.com/mysql/MySQL-5.5/ From: http://www.cnblogs.com/magicsoar/p/3817518.html C+ ...
- Mybatis Plus带多条件的多表联合、分页、排序查询
目录 一.现有表 student学生表: facultylist学院表: 二.同时满足以下需求: 1.多表联合查询出学院名字 2.可以带多条件查询 3.指定页码,页数据大小进行物理分页查询 三.解决步 ...
- Dao设计模式简单实现
一.什么是Dao设计模式 Dao设计模式封装了操作具体数据库的细节,对业务层提供操作数据库的接口,因此降低了业务层代码与具体数据库之间的耦合,有利于人员分工,增加了程序的可移植性. Dao设计模式中主 ...