美文网首页
笔记04 category

笔记04 category

作者: PPFSaber | 来源:发表于2021-03-12 17:38 被阅读0次

四 category



越靠后编译的分类方法插入的越靠前,即优先级越高,编译顺序在 compile source 里


分类的属性
1 声明 分类的属性系统只会帮你声明 set和get 方法,不会实现这两个方法,需要你自己去实现
@property (copy, nonatomic) NSString* name;

关联对象

另一种方式 
#define MJKey [NSString stringWithFormat:@"%p", self]
@implementation MJPerson (Test)

NSMutableDictionary *names_;
NSMutableDictionary *weights_;
+ (void)load
{
    weights_ = [NSMutableDictionary dictionary];
    names_ = [NSMutableDictionary dictionary];
}

- (void)setName:(NSString *)name
{
//    NSString *key = [NSString stringWithFormat:@"%p", self];
    names_[MJKey] = name;
}

- (NSString *)name
{
//    NSString *key = [NSString stringWithFormat:@"%p", self];
    return names_[MJKey];
}

- (void)setWeight:(int)weight
{
//    NSString *key = [NSString stringWithFormat:@"%p", self];
    weights_[MJKey] = @(weight);
}

- (int)weight
{
//    NSString *key = [NSString stringWithFormat:@"%p", self];
    return [weights_[MJKey] intValue];
}
@end

相关文章

  • 笔记04 category

    四 category 越靠后编译的分类方法插入的越靠前,即优先级越高,编译顺序在 compile source 里...

  • 手机解锁抛光文字

    笔记效果图 创建UIView的Category 使用

  • Category笔记

    为什么Category无法添加实例变量? Category是无法添加实例变量的,当一个类被编译时,实例变量的布局也...

  • category 笔记

    1.category 网上很多种叫法,分类/类别/类目,它是OC的特有语法,作用是在不改变原来类的基础上为这个类扩...

  • 笔记 - Category

    1、Category的基本使用 2、Category的实现原理? 3、源码分析1 objc4-723.tar.gz...

  • AndroidHeroes读书笔记

    title: AndroidHeroes读书笔记category: Androiddate: 2016-3-15t...

  • 《极简主义》读书笔记

    title: "《极简主义》读书笔记"category: "Life Discovery"tag: ["Misce...

  • 《Python入门教程完整版》笔记和视频地址

    笔记:https://www.zrahh.com/category/biji/2/视频:https://www.b...

  • 如何理解我思故我在

    title: 如何理解我思故我在date: 2019-4-10category:- 读书笔记tag:- 读书笔记 ...

  • Category理解笔记

    先自我想想下面关于 Category 思考题: Category能否添加成员变量?如果可以,如何给Category...

网友评论

      本文标题:笔记04 category

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