zoukankan      html  css  js  c++  java
  • OC4_遵守多个协议

    //
    //  Calulator.h
    //  OC4_遵守多个协议
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "Adder.h"
    #import "Subber.h"
    #import "Multter.h"
    #import "Divver.h"
    
    //遵守多个协议, 协议之间用逗号隔开
    @interface Calulator : NSObject <Adder,Subber,Multter,Divver>
    
    @end
    
    
    //
    //  Calulator.m
    //  OC4_遵守多个协议
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "Calulator.h"
    
    @implementation Calulator
    
    + (int)addA:(int)a andB:(int)b
    {
        return a+b;
    }
    
    + (int)subA:(int)a andB:(int)b
    {
        return a-b;
    }
    
    + (int)divA:(int)a andB:(int)b
    {
        return a/b;
    }
    
    + (int)mulA:(int)a andB:(int)b
    {
        return a*b;
    }
    
    @end
    //
    //  Divver.h
    //  OC4_遵守多个协议
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @protocol Divver <NSObject>
    
    + (int)divA:(int)a andB:(int)b;
    
    @end
    
    
    //
    //  Multter.h
    //  OC4_遵守多个协议
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @protocol Multter <NSObject>
    
    + (int)mulA:(int)a andB:(int)b;
    
    @end
    
    
    //
    //  Subber.h
    //  OC4_遵守多个协议
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @protocol Subber <NSObject>
    
    + (int)subA:(int)a andB:(int)b;
    
    @end
    
    
    //
    //  Adder.h
    //  OC4_遵守多个协议
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @protocol Adder <NSObject>
    
    + (int)addA:(int)a andB:(int)b;
    
    @end
    //
    //  main.m
    //  OC4_遵守多个协议
    //
    //  Created by zhangxueming on 15/6/24.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "Calulator.h"
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            // insert code here...
            NSLog(@"add = %i", [Calulator addA:3 andB:5]);
            NSLog(@"mul = %i", [Calulator mulA:5 andB:10]);
        }
        return 0;
    }
  • 相关阅读:
    为什么Go没有三元运算符
    [Win10]鼠标没用,插入USB口电脑提示USB Optical Mouse找不到驱动程序的解决方案
    Office2016软件安装教程
    office2019软件安装教程
    Go语言 科学计算库 Gonum 学习1
    AI Studio 学习 Go 豆瓣电影爬取
    Git下载、安装与环境配置
    VueJS 数组哪些方法是响应式的
    VueJS v-for
    VueJS v-show
  • 原文地址:https://www.cnblogs.com/0515offer/p/4598507.html
Copyright © 2011-2022 走看看