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

  • 相关阅读:
    J. 最大权边独立集 题解(树上背包)
    F. 地图压缩 题解(kmp 最小循环节)
    Sum of Log 题解(数位dp)
    F. Scalar Queries 题解(思维+线段树)
    B. 攻防演练 题解(思维+倍增)
    Bit Sequence 题解(数位dp)
    机器学习
    Android学习笔记
    sqoop
    Initialization failed for block pool Block pool
  • 原文地址:https://www.cnblogs.com/chenxiangxi/p/2456781.html
Copyright © 2011-2022 走看看