zoukankan      html  css  js  c++  java
  • ObjectiveC 注意要点

    Objective-C注意要点

    1、没有C++中的bool值,对应的类型为BOOL,聚会为YES、NO.

    2、定义

    @interface Car

    {

    int m_nWeight;

    int m_nSpeed;

    }

    @property int m_nWeight;

    @proprety (readonly) int m_nSpeed;

    // 名字关联

    @property int speed;

    @synthesize speed = m_nSpeed;

    @end

    3、实现

    @implementation Car

    @synthesize m_nWeight;

    @synthesize m_nSpeed;

    @end

    4、调用

    [self setSpeed:speed];

    Car *pCar = [Car new];

    Car *pCar = [[Car alloc] init];

    5、没有private、protected、public访问控制,所有东西都是public

    6、无法设置函数默认参数的特性

    7、Categories特性使得我们可以给已有的类添加新的接口。

    @interface Car (CarDescription)

    @implementation Car (CarDescription)

    在使用的时候,无需单独import Cardescription.h。

    只要import 了Car.h 编译器会自己关联Car相关的categories。

    注意:Category的使用要注意两点:一是Category中不能声明新的成员变量。

    8、协议

    @protocol NSCopying

    @optional

    @required

    - (id) copyWithZone: (NSZone*) zone;

    @end

    @interface Car: NSObject <NSCopying>

  • 相关阅读:
    0814防盗链访问控制代理
    0811Nginx访问日志设置
    0810Nginx安装
    0809LNMP架构介绍
    PHP安装
    mariaDB安装Apache安装(httpd)
    LAMP构架介绍
    shell基础知识(2)
    shell基础知识(1)
    yum更换国内源、yum下载rpm包、源码包安装
  • 原文地址:https://www.cnblogs.com/tekkaman/p/2169058.html
Copyright © 2011-2022 走看看