码迷,mamicode.com
首页 > 其他好文 > 详细

OC基础 类别

时间:2020-06-29 00:20:44      阅读:61      评论:0      收藏:0      [点我收藏+]

标签:sel   技术   loading   span   pre   类别   width   log   lazy   

 

类别的创建

 

 

 

 

技术图片

 

 integer.h

@interface integer : NSObject
@property int integer;
@end

 

integer.m

@implementation integer

@end

 

类别 

integer+display.h
integer+display.m

 

#import <Cocoa/Cocoa.h>
#import "integer.h"
NS_ASSUME_NONNULL_BEGIN
// 类别 没有成员变量

@interface integer(display) //原有类名(类别名)

-(void)show;
-(void)add:(integer*)other;
-(void)sub:(integer*)other;
-(void)mul:(integer*)other;
-(void)div:(integer*)other;
@end
#import "integer+display.h"

@implementation integer(display)
-(void)show
{
    
    
//    NSLog(@"hello world");
    NSLog(@"%i",self.integer);
}
    
-(void)add:(integer*)other
    {
        self.integer+=other.integer;
        
    }

-(void)sub:(integer*)other
{
    
    self.integer-=other.integer;
    
}
-(void)mul:(integer*)other
{
    self.integer*=other.integer;
}
-(void)div:(integer*)other
{
    if(other.integer!=0)
    {
        
        self.integer/=other.integer;
        
    }
    
}
@end

 

OC基础 类别

标签:sel   技术   loading   span   pre   类别   width   log   lazy   

原文地址:https://www.cnblogs.com/zhangqing979797/p/13205530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!