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的陷阱中。

  • 相关阅读:
    Angular 学习笔记 (消毒 sanitizer)
    资源链接
    QM作品
    读书笔记
    javascript jQuery遇到的小问题 不定添加
    css 平时遇见CSS的一些小技巧 不定添加
    html 小却重要的问题 不定添加
    Array 对象
    test
    Javascript定义类(class)的三种方法
  • 原文地址:https://www.cnblogs.com/chenxiangxi/p/2456781.html
Copyright © 2011-2022 走看看