zoukankan      html  css  js  c++  java
  • const static 在oc中的用法

    const表示不能修改  static表示作用域限定在本文件中

    // EOCAnimatedView.h
    #import <UIKit/UIKit.h>

    @interface EOCAnimatedView : UIView
    - (void)animate;
    @end

    // EOCAnimatedView.m
    #import "EOCAnimatedView.h"

    static const NSTimeInterval kAnimationDuration = 0.3;

    @implementation EOCAnimatedView
    - (void)animate {
        [UIView animateWithDuration:kAnimationDuration
                         animations:^(){
                             // Perform animations
                         }];
    }
    @end

    It is important that the variable is declared as both static and const. The const qualifier means that the compiler will throw an error if you try to alter the value. In this scenario, that’s exactly what is required. The value shouldn’t be allowed to change. The staticqualifier means that the variable is local to the translation unit in which it is defined. A translation unit is the input the compiler receives to generate one object file. In the case of Objective-C, this usually means that there is one translation unit per class: every implementation (.m) file. So in the preceding example, kAnimationDuration will be declared locally to the object file generated from EOCAnimatedView.m. If the variable were not declared static, the compiler would create an external symbol for it. If another translation unit also declared a variable with the same name, the linker would throw an error with a message similar to this:

    duplicate symbol _kAnimationDuration in:
        EOCAnimatedView.o
        EOCOtherView.o

  • 相关阅读:
    yes---重复输出指定的字符串
    info---Linux下info格式的帮助指令。
    hostid---打印当前主机的十六进制数字标识
    clear---清除当前屏幕
    whoami---打印当前有效的用户名称
    users---显示当前登录系统的所有用户的用户列表
    md5sum---文件校验和
    mesg---设置当前终端的写权限
    man帮助
    whatis---查询一个命令执行什么功能
  • 原文地址:https://www.cnblogs.com/NSNULL/p/4489641.html
Copyright © 2011-2022 走看看