类别:(Category)

作者: i赵磊 | 来源:发表于2016-06-03 10:17 被阅读50次
类别的创建⬇️
屏幕快照 2016-05-22 下午4.17.46.png
类别的.h文件
#import <Foundation/Foundation.h>
@interface NSString (NSLog)
-(void)nslogMyWord;`//方法的声明
@end
类别的.m文件
#import "NSString+NSLog.h"
@implementation NSString (NSLog)
-(void)nslogMyWord{`//方法的实现部分

      NSLog(@"消息被成功打印");
}
@end
ViewController的.m文件
#import "ViewController.h"
#import "NSString+NSLog.h"//导入类别文件
@interface ViewController ()
@end
@implementation ViewController`
- (void)viewDidLoad {`

    [super viewDidLoad];
    NSString *string=[[NSString alloc]init];
    [string nslogMyWord]; //调用类别方法
}
@end

相关文章

网友评论

    本文标题:类别:(Category)

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