zoukankan      html  css  js  c++  java
  • Category-分类

    概念

    1OC中提供了一种与众不同的方式-Category,可以动态地为经已存在的类添加新的方法。

    变态啊,不改变.m 和.h

    2可以保证类的原始设计规模大小,功能增加时再逐步扩展。

    3Category使用简单的方式,实现了类的相关方法的模块化,把不同的类方法分配到不同的文件中。

    只是方法,不能拓展成员变量

    -----------------------------------

    new->Cocoa->OC category

    Category: Test

    Category on: Student

    Create as

    Student+Test.h

    Student+Test.m

    ----------------------------------------

    Student+Test.h

    #import "Student.h"

    @interface Student(Test)

    //()代表分类     :代表继承 Test分类名称

    fg

    @end 

    //注意不能用 @class Student, 因为要使用它的方法。

    Student+Test.m

    #import "Student+Test.h"

    //Realization

    main.m

    #import "Student+Test.h"

    Student *stu=[[Student alloc]init];

    [stu test];

    [stu test2];

    [stu release];

  • 相关阅读:
    我要把铁路修到威斯特摩兰
    1新建空白jasperreport模板
    oracle权限
    swagger配置
    lombok插件基本使用
    oracle与sqlserver的区别
    yaml语法学习
    第一个SpringBoot
    spring多环境切换
    JSR303数据校验
  • 原文地址:https://www.cnblogs.com/yesihoang/p/4495689.html
Copyright © 2011-2022 走看看