美文网首页
iOS协议使用

iOS协议使用

作者: 拥抱月亮的大星星 | 来源:发表于2018-11-01 11:53 被阅读19次

协议A

#import <Foundation/Foundation.h>


@protocol ProtocolADelegate <NSObject>

- (void)say;

@end

实现地方

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    // Do any additional setup after loading the view, typically from a nib.
}


-(void)say{
    NSLog(@"hello");
}

@end

调用触发

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    
    
    NSMutableArray <id<NSObject>> * array = [@[[[ViewController alloc]init]] mutableCopy];
    
    id <ProtocolADelegate> module = array.firstObject;
    
    
    
    [module say];
    
    return YES;
}

相关文章

网友评论

      本文标题:iOS协议使用

      本文链接:https://www.haomeiwen.com/subject/piotxqtx.html