zoukankan      html  css  js  c++  java
  • Working with nil

    Working with nil

      It’s always a good idea to initialize scalar variables at the time you declare them, otherwise their initial values will contain garbage from the previous stack contents:

      

      This isn’t necessary for object pointers, because the compiler will automatically set the variable to nil if you don’t specify any other initial value:

      

      A nil value is the safest way to initialize an object pointer if you don’t have another value to use, because it’s perfectly acceptable in Objective-C to send a message to nil. If you do send a message to nil, obviously nothing happens.

      Note: If you expect a return value from a message sent to nil, the return value will be nil for object return types, 0 for numeric types, and NO for BOOL types. Returned structures have all members initialized to zero.

      If you need to check to make sure an object is not nil (that a variable points to an object in memory), you can either use the standard C inequality operator:

      

      or simply supply the variable:

      

      If the somePerson variable is nil, its logical value is 0 (false). If it has an address, it’s not zero, so evaluates as true.

    Similarly, if you need to check for a nil variable, you can either use the equality operator:

      

      or just use the C logical negation operator:

      

  • 相关阅读:
    索引的使用说明
    如何在Linux 发行版本CentOS安装Oracle
    GNU/Linux 初學之旅
    Oracle数据库监听配置(转)
    Linux学习笔记7用户建立密码设置及删除用户
    Linux学习笔记6ls命令
    linux vi命令使用
    生成1千万个随机串号9位英文字母
    郁闷的夏天
    网络爬虫
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3550942.html
Copyright © 2011-2022 走看看