首页 > 其他 > 详细

OC基础 类别

时间:2020-06-29 00:03:28      阅读:69      评论:0      收藏:0      [点我收藏+]

 

类别的创建

 

 

 

 

技术分享图片

 

 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基础 类别

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!