• IOS常见语法解惑


    由于工作过程中经常需要查看IOS的Objective-C代码,遂把一些常见的、有疑问的OC语法列出,方便之后会看,提升效率。

    Objective-C中的@语法

    @interface告诉编译器,我要声明一个新类,包含了类的属性和方法,以@end结尾;

    @implementation告诉编译器,这是某个类的具体实现,以@end结尾;

    @property是声明属性的语法,它可以快速方便的为类的成员变量创建存取器,并允许我们通过点语法使用存取器,@property等同于在.h文件中声明实例变量的get/set方法,@synthesize等同于在.m文件中实现实例变量的get/set方法。需要注意的是@property可以直接给成员变量赋特性,如nonatomic表示非原子的,assign表示值类型。

    声明通常放在类的头文件中,代码示例如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    @interface BatteryInfo: NSObject
    NSInteger _batteryLevel;
    CGFloat _current;
    }
    - (void)showBatteryInfo;
    @property (nonatomic, assign) NSInteger batteryLevel;
    @property (nonatomic, assign) CGFloat current;
    @end

    实现通常放在类的.m文件中,代码示例如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    @implementation BatteryInfo
    - (void)showBatteryInfo
    {
    //TODO
    }
    @synthesize batteryLevel = _batteryLevel;
    @synthesize current = _current;
    @end

    Objective-C中的函数调用语法

  • 相关阅读:
    [转载]setup factory使用方法
    MFC中调用WPF教程
    Reduce the Number of SQL Statements
    Library Cache Hit Ratio
    Seconds in wait
    PX Deq: Execute Reply等待事件
    RoundTrip Time
    Changing an Init.ora Parameter
    PX qref latch等待事件
    提高DBWR进程的吞吐量
  • 原文地址:https://www.cnblogs.com/lijianming180/p/12360870.html
Copyright © 2020-2023  润新知