zoukankan      html  css  js  c++  java
  • OC语法9——Category类别

    Category(分类):

      当我们在开发过程中要给类添加新的方法时,一般不要去动原类。

      再不改动原类的限制下,怎么拓展类的方法?以往我们的做法是新建子类使其继承该类,然后通过子类拓展类的行为。

      OC提供了一种全新的方法:Category(分类)。在不改动原类的基础上动态的拓展类的行为。

      假如我们要动态拓展Student类,则应该建一个分类(Category),注意:文件命名要有规范,Student+StuOthers.h

      格式:只要在被扩展的类名(原类)后加(),在括号里写分类名(拓展类名);

        Student+StuOthers.h中

    #import "Student.h"
    @interface Student (StuOthers)   //括号里就是分类名
    - void test();
    @end

        Student+StuOthers.m中

    #import "Student+StuOthers.h"
    @implementation Student (StuOthers)
    - void test()
    {
        @NSLog(@"wanger");
    }
    @end
  • 相关阅读:
    govalidators 验证
    go iris框架 获取url的两种方法
    tornado框架
    并发/并行,阻塞/非阻塞,同步/异步
    CSS选择器及优先级
    linux下压力测试命令ab
    asyncio
    linux网络原理及基础设置
    linux命令
    linux简介
  • 原文地址:https://www.cnblogs.com/wangerxiansheng/p/4297296.html
Copyright © 2011-2022 走看看