zoukankan      html  css  js  c++  java
  • OC-改错题

    1,类方法中不能访问成员变量

    2,id后不能加*(因为id相当于NSObject *)

    3,id类型的变量不能用点语法

    4,类对象只能调用类方法,不能调用对象方法

    1.description
    #import <Foundation/Foundation.h>
    @interface Person : NSObject
    @property int age;
    @end
    
    @implementation Person
    // 类方法中不能访问成员变量
    //+ (NSString *)description
    - (NSString *)description
    {
        return [NSString stringWithFormat:@"_age=%d", _age];
    }
    @end
    
    // 1个错误
    
    /*-------------------------牛B的分隔线-------------------------*/
    
    2.id、SEL、类对象
    #import <Foundation/Foundation.h>
    @interface Person : NSObject
    - (void)test;
    @property int age;
    @end
    
    @implementation Person
    - (void)test
    {
        // 会引发死循环错误
        //[self performSelector:_cmd];
    }
    @end
    
    int main()
    {
        // id后面不能加上*
        //id *p = [[Person alloc] init];
        id p = [[Person alloc] init];
        [p setAge:10];
        
        // id类型的变量不能用点语法
        // p.age = 10;
        
        Class c = [Person class];
        // 类对象只能调用类方法,不能调用对象方法
        //[c test];
        
        return 0;
    }
  • 相关阅读:
    批处理学习总结之常用命令1
    Delphi常用数据类型
    Delphi预编译指令总结
    Delphi同步互斥总结
    MyEclipse 环境配置总结
    倒排索引
    laravel 学习相关笔记
    elasticsearch倒排索引原理
    原生sql和 TP sql怎么关联?
    elastic
  • 原文地址:https://www.cnblogs.com/IDRI/p/4957372.html
Copyright © 2011-2022 走看看