Ray's playground

 

Extensions to C(Chapter 2 of Learn Objective-C on the Mac)

1 #import <Foundation/Foundation.h>
2 int main (int argc, const char *argv[])
3 {
4   NSLog (@"Hello, Objective- C!");
5   return (0);
6 // main

 

BOOL
 1 #import <Foundation/Foundation.h>
 2 // returns NO if the two integers have the same
 3 // value, YES otherwise
 4 BOOL areIntsDifferent (int thing1, int thing2)
 5 {
 6   if (thing1 == thing2) 
 7   {
 8     return (NO);
 9   } 
10   else 
11   {
12     return (YES);
13   }
14 // areIntsDifferent
15 
16 // given a YES value, return the human- readable
17 // string "YES". Otherwise return "NO"
18 NSString *boolString (BOOL yesNo)
19 {
20   if (yesNo == NO) 
21   {
22     return (@"NO");
23   } 
24   else 
25   {
26     return (@"YES");
27   }
28 // boolString
29 
30 int main (int argc, const char *argv[])
31 {
32   BOOL areTheyDifferent;
33   areTheyDifferent = areIntsDifferent (55);
34   NSLog (@"are %d and %d different? %@"55, boolString(areTheyDifferent));
35   areTheyDifferent = areIntsDifferent (2342);
36   NSLog (@"are %d and %d different? %@"2342, boolString(areTheyDifferent));
37   return (0);
38 // main

 

 

posted on 2010-05-06 19:32  Ray Z  阅读(342)  评论(0编辑  收藏  举报

导航