objective-c协议

本文详细解析了iOS开发中的关键技术和Swift编程语言的高级特性,包括UI设计、性能优化、错误处理和协程编程等内容。通过实战案例,为开发者提供了一站式的技术解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一,协议的定义

@protocol test

-(void) testpocol:(int)t;

@end

二,协议的继承

h头文件

#import “test.h” 导入协议

@interface testViewController:UIViewController <test>{

//id<test> testp;

}

m实现文件

@implementation testViewController

-(void)viewDidLoad{

[super viewDidLoad];

//调用实现方法的类

testdiaoyong *td=[[testdiaoyong alloc] init];

td.testd=self; 把当前实现协议的类对象赋给需要使用的地方

//也可以使用下面的方法传递协议

[td setpoco:self]

}

-(void) testpocol:(int)s{

NSLog(@"testpocol...............................................................%d",s);

}

@end

三,调用协议

@interface testdiaoyong : NSObject{

id<test> testp;

}

-(void)setpoco:t;

-(void)setlen;

@end

@implementation testdiaoyong

@synthesize testp;

//协议t可以不负类型

-(void)setpoco:t{

self.testp=t;

}

-(void)start{

[testp testpocol:99];

}

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值