041.extension 类的拓展
来源:互联网 发布:淘宝的老凤祥是真的吗 编辑:程序博客网 时间:2024/06/07 17:19
--------------- FKCar.h ---------------
#import <Foundation/Foundation.h>
@interface FKCar : NSObject
@property (nonatomic , copy) NSString* brand;
@property (nonatomic , copy) NSString* model;
- (void) drive;
@property (nonatomic , copy) NSString* brand;
@property (nonatomic , copy) NSString* model;
- (void) drive;
@end
--------------- FKCar.m ---------------
#import "FKCar+drive.h"
@implementation FKCar
- (void) drive;
{
- (void) drive;
{
NSLog(@"%@汽车正在路上奔驰", self);
}
- (void) drive:(NSString*) owner
{
- (void) drive:(NSString*) owner
{
NSLog(@"%@正驾驶%@汽车在路上奔驰", owner , self);
}
- (NSString*) description
{
- (NSString*) description
{
return [NSString stringWithFormat:@"<FK[_brand=%@,_model=%@,_color=%@]>"
, self.brand , self.model ,self.color];
}
@end
--------------- FKCar+drive.h ---------------
#import "FKCar.h"
@interface FKCar ()
@property (nonatomic , copy) NSString* color;
- (void) drive:(NSString*)owner;
@interface FKCar ()
@property (nonatomic , copy) NSString* color;
- (void) drive:(NSString*)owner;
@end
--------------- main.m ---------------
#import <Foundation/Foundation.h>
#import "FKCar+drive.h"
int main()
{
FKCar* car = [[FKCar alloc] init];
car.brand = @"宝马";
car.model = @"X5";
car.color = @"黑色";
[car drive];
[car drive:@"孙悟空"];
int main()
{
FKCar* car = [[FKCar alloc] init];
car.brand = @"宝马";
car.model = @"X5";
car.color = @"黑色";
[car drive];
[car drive:@"孙悟空"];
}
一、编写本节代码的具体步骤:
1.可仿照第二章001节的代码编写步骤。
2.FKCar+drive.h文件需要另行创建。
二、本节代码涉及到的知识点:
1.拓展的写法是 @interface 加上 已有类的类名 加上 () 加上 花括号。
花括号里面写实例变量和方法。
2.注意:拓展可以增加实例变量和方法,而前面学的category类别只能增加方法。
3.注意,FKCar.m文件中,要导入FKCar+drive.h文件。
0 0
- 041.extension 类的拓展
- 041.extension 类的拓展
- 041.extension 类的拓展
- OC学习第七天_2 类的拓展 Category Extension Protocol delegate
- C# 类,接口的拓展
- JDK类库的拓展
- ios开发之分享应用拓展share extension一
- iOS10通知及通知拓展Extension使用详解
- Category和extension(扩展类的功能)
- 类的扩展-category和extension
- 拓展控件 - 拓展的TextView
- IOS系列——类的拓展
- Python3基础(十一) 类的拓展
- Obiect-C之Category(类的拓展)
- OC整理 类的拓展,内存管理
- pjsip的sip extension
- chromium extension的binding
- Firefox的extension
- 019 Remove Nth Node From End of List [Leetcode]
- 042.@interface 非正式协议(category)
- Ugly Number
- linux操作命令
- C# 不复制到本地(软件当前目录)引用程序集;
- 041.extension 类的拓展
- Listview or GridView中嵌套cardview解决方案
- python与zmq系列(2)
- 如何在docker容器中运行一个程序
- Android开发,将图片(bitmap)变成圆形图片、图片文件变成bitmap的方法
- 解决jenkins打包时不能及时更新到最新代码的问题
- 仿qq记录历史账号
- 041.extension 类的拓展
- linux系统安装(二)-远程登录管理工具SecureCRT