zoukankan      html  css  js  c++  java
  • 系统学习ObjectiveC<基础>

     1 #import <Foundation/Foundation.h>
     2 BOOL areInstDifferent(int thing1, int thing2);
     3 NSString *boolString(BOOL yesNO);
     4 BOOL areInstDifferent(int thing1, int thing2)
     5 {
     6     if(thing1 == thing2)
     7     {
     8         return (NO);
     9     }
    10     else
    11    {
    12         return (YES);
    13    }
    14 }
    15 
    16 NSString *boolString(BOOL yesNO)
    17 {
    18     if(yesNO == NO)
    19     {
    20          return (@"NO");
    21     }
    22     else
    23     {
    24          return (@"YES");
    25     }
    26 }
    27 
    28 int main(int argc, const char * argv[])
    29 {
    30      @autoreleasepool
    31      {
    32           BOOL areTheyDifferent;
    33           areTheyDifferent = areIntsDifferent(5, 5);
    34           NSLog(@"are %d and %d different? %@", 5, 5, boolString(areTheyDifferent));
    35           areTheyDifferent = areIntsDifferent(23, 42);
    36           NSLog(@"are %d and %d different? %@", 23, 42, boolString(areTheyDifferent));
    37      }
    38      return 0;
    39 }

    以上简单的代码就是对Objective-C的很好的解释,跟C语言区别不是很大,但也有不同,值得注意的就是:#import <Foundation/Foundation.h>、NSLog(@"");、BOOL的使用,要特别注意以上三个与C语言中的区别,不要掉进BOOL的陷阱中。

  • 相关阅读:
    java集合归纳
    判断回文数
    29:四则运算计算表达式的值
    getOutString 输出弹出字符串
    两个字符串中不同元素的个数
    字符串各个字符ASCII值加5
    23:一个整数的二进制表示中有多少个1
    Java进程间通信
    转 双重检查锁定与延迟初始化
    Key-Value键值存储原理初识(NOSQL)
  • 原文地址:https://www.cnblogs.com/chenxiangxi/p/2456781.html
Copyright © 2011-2022 走看看