4

Objective-C 的协议

 3 years ago
source link: http://blog.danthought.com/programming/2020/12/03/objective-c-protocol/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Objective-C 的协议

博客来自于但江的思考,关于编程、设计、商业和生活

Objective-C 的协议

本文并不是一篇完整的教程,更像一篇快速笔记,讲解 Objective-C 中的协议。

Objective C

协议列出了一组方法,有些可以是选择实现,有些是必须实现,如果决定实现特定协议的所有方法,也就意味着遵守这项协议:

  1. @required 后面的方法是必须实现,默认都是必须实现;
  2. @optional 后面的方法是选择实现。
@class PWListener;

@protocol PWListenerDelegate <NSObject>

- (void)listenerDidStartSuccess:(PWListener *)listener;
- (void)listenerDidStartFailed:(PWListener *)listener;
- (void)listener:(PWListener *)listener didConnectDevice:(PWLocalDevice *)device;

@end

@interface PWListener : NSObject

@property (weak, nonatomic) id<PWListenerDelegate> delegate;

- (instancetype)initWithAbility:(PWAbility *)ability port:(NSInteger)port;

- (void)start;

@end

如果你觉得以上思考对你有帮助,请订阅博客


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK