学习objective-c问题汇总

移动开发 iOS
终于全部实践了一次并写了一些小小的东西,不过还是不太熟练。接下来会继续看另外一本很基础的书,不过这本书就不会做笔记了,同时会跟着新买的一本口碑超赞的书进行实践练习,会有新笔记的。

1、在xcode中无法在一个窗口打开多个项目,每个窗口只能存在一个项目。

  解决方案:cmd+~,就是tab上面一个键,可以在项目中快速切换。

2、conflicting types for ‘方法名’ 的错误。(Objective-C基础教程第三章中***个实例练习时出错)

  解决方案:这里走的是C的语法,每个被调用的函数都需要在调用之前被声明。

3、Must explicitly describe intended ownership of an object array parameter(Objective-C基础教程第三章中***一个实例练习时出错)


进行到第三章***一个实例时,cmd+r运行会报错:Must explicitly describe intended ownership of an object array parameter。如 果你看到了这个错误信息,你可以选中左边的项目名,然后再选中右边的PROJECT-->Apple LLVM compiler 4.2 - Language-->Objective-C Automatic Reference Counting,它本来的值是Yes,将它的值改为No(不自动管理内存),就可以正常编译运行了(如下截图所示)。


错误的大概意思是,必须为方法中数组参数分配明确地空间。

4、继承的工作机制:方法调度和实例变量

方法调度:发送消息时,首先在当前类中查找该方法,如果没有,则向该方法的superclass中进行查找。

实例变量:从上往下查找?实例变量不存在重新声明的情况吧?(⊙o⊙)…不太明。。(脆弱的基类问题?不懂。。mark)

5、linker command failed with exit code 1 (use -v to see invocation)(第六章切割文件时遇到)

参考:http://blog.csdn.net/duxinfeng2010/article/details/8265273

6、@class Tire;     // 使用方法和位置与 #import类似

@class 创建一个前向引用,并声明只会通过指针来引用该类。可以通过@class 让两个类互相引用。即,在A.h中用@class B,在B.h 中用@class A。但如果用 #import 让这两个类互相引用,就会出现编译错误。

7、在敲NSRange这章内容时,遇到一个纠结的问题,通过{5,5}或者NSMakeRange(5,5)给NSRange对象赋值会报错


其实是我自己犯傻,照着书copy,将NSRange重定义了,自然会出错了。

8、方法名前面的 + 与 -

最开始让我觉得无语的是,objective-c在方法前面加上的+和-,不过现在觉得挺好的,一目了然。

+:说明该方法是类方法,通常用于创建新的实例。例如,+ (id)stringWithFormat:(NSString *)format,...;

-:该方法为实例方法,我们直接在类中定义的起一定作用的方法。

9、NSArray的两个限制:只能存储objective-c对象,不能存储原始c数据类型;不能存储nil。

10、NSEnumerator 数组循环报错问题

  1. NSArray *array = @[@"marong",@"hello"];   
  2.  
  3.          NSEnumerator *enumerator = [array objectEnumerator];   
  4.  
  5.         id thingie = [enumerator nextObject];   
  6.  
  7.          while (thingie) {   
  8.  
  9.              NSLog(@"I found %@", thingie);   
  10.  
  11.              thingie = [enumerator nextObject];   
  12.  
  13.          }  

书中将 

  1. id thingie = [enumerator nextObject]; 

while表达式中,报错,我将该句移到循环体外面,并在循环体内加上迭代语句,然后正常。

11、可变string、可变array和可变dictionary

12、NSNull,只有一个方法:+(NSNull *)null;

13、这么一个小程序也能让我觉得有趣啊

  1. #import <Foundation/Foundation.h>   
  2.  
  3.     
  4.  
  5.  int main(int argc, const char * argv[])   
  6.  
  7.  {   
  8.  
  9.     
  10.  
  11.     @autoreleasepool {   
  12.  
  13.              
  14.  
  15.         NSFileManager *manager;   
  16.  
  17.         manager = [NSFileManager defaultManager];   
  18.  
  19.              
  20.  
  21.          NSString *home;   
  22.  
  23.         home = [@"~" stringByExpandingTildeInPath];   
  24.  
  25.              
  26.  
  27.         NSDirectoryEnumerator *direnum;   
  28.  
  29.          direnum = [manager enumeratorAtPath:home];   
  30.  
  31.             
  32.  
  33.          NSMutableArray *files;   
  34.  
  35.          files = [NSMutableArray arrayWithCapacity:42];   
  36.  
  37.              
  38.  
  39.          NSString *filename;   
  40.  
  41.         while (filename = [direnum nextObject]) {   
  42.  
  43.             if ([[filename pathExtension] isEqualTo: @"jpg"]) {   
  44.  
  45.                  [files addObject:filename];   
  46.  
  47.              }   
  48.  
  49.          }   
  50.  
  51.              
  52.  
  53.          NSEnumerator *fileenum;   
  54.  
  55.          fileenum = [files objectEnumerator];   
  56.  
  57.              
  58.  
  59.          while (filename = [fileenum nextObject]) {   
  60.  
  61.              NSLog(@"%@",filename);   
  62.  
  63.          }   
  64.  
  65.              
  66.  
  67.      }   
  68.  
  69.     return 0;   
  70.  
  71.  }  

我发现我对所谓JS的各种特效越来越不耐烦,如果再没有一个统一的标准,日渐庞大而 臃肿的JS队伍最终将溃不成军。一个写后台的同事问我,你为什么不写程序啊,我觉得你挺适合写程序的,你为什么选择切页面这种工作呢?是的,把时间都花在 无谓的特效与动画上,而遗忘了自己的本质,不管是在别人眼中还是在你自己心里,永远都只是个切页面的。

无谓身边人如何唱衰 IOS,不过我却觉得有意思起来。没有太多奇葩兼容的苦恼,虽然也要兼容低版本系统,可是相比web和android的兼容问题,那都是毛毛雨。系统现成 的特效,可以把更多地精力花在业务逻辑和性能优化上,毕竟总得走的更远一点,只做一个程序员还是欠缺点什么。

14、关于快速枚举的一点不明:filewalkerV2实例中的片段

快速枚举使用的语法:
for ( Type newVariable in expression ) { statements }
for ( existingItem in expression ) { statements }
枚举期间对象不能被改变。
使用快速枚举的三个类:
NSArray, NSDictionary, NSSet

快速枚举的特性:可以将已有的NSEnumerator 对象或其子类传递给它。

  1. NSFileManager *manager;   
  2.  
  3.        manager = [NSFileManager defaultManager];   
  4.  
  5.            
  6.  
  7.        NSString *home;   
  8.  
  9.       home = [@"~" stringByExpandingTildeInPath];   
  10.  
  11.           
  12.  
  13.       NSMutableArray *files;   
  14.  
  15.       files = [NSMutableArray arrayWithCapacity:50];   
  16.  
  17.            
  18.  
  19.        // [manager enumeratorAtPath:home] 的返回值类型为 NSDirectoryEnumerator   
  20.  
  21.        for (NSString *filename in [manager enumeratorAtPath:home]) {   
  22.  
  23.            if ([[filename pathExtension] isEqualTo: @"jpg"]){   
  24.  
  25.                [files addObject:filename];   
  26.  
  27.           }   
  28.  
  29.        }   
  30.  
  31.           
  32.  
  33.        for (NSString * filename in files) {   
  34.  
  35.           NSLog(@"%@", filename);   
  36.  
  37.        }  

15、内存管理,很不明,mark

现在貌似用不到书上也就是后面截图那些了,自动生成的main函数中都会有下面这段代码:

  1. @autoreleasepool {   
  2.  
  3.     // do something here          
  4.  
  5. }  



 

16、使用 NSString 的 convenience initializer 方法initWithContentsOfFile读取文件

 

  1. int main(int argc, const char * argv[])   
  2.  
  3.  {       
  4.  
  5.      NSFileManager *manager;   
  6.  
  7.     manager = [NSFileManager defaultManager];   
  8.  
  9.          
  10.  
  11.     NSString *home;   
  12.  
  13.     home = [@"~" stringByExpandingTildeInPath];   
  14.  
  15.          
  16.  
  17.     NSLog(@"%@", home);   
  18.  
  19.     NSString *path;   
  20.  
  21.      path = [NSString stringWithFormat:@"%@/Documents/studyfile/资料网站搜集.txt", home];   
  22.  
  23.         
  24.  
  25.      NSString *filestring;   
  26.  
  27.     filestring = [[NSString alloc]   
  28.  
  29.                    initWithContentsOfFile: path];   
  30.  
  31.          
  32.  
  33.     NSLog(@"%@", filestring);   
  34.  
  35.           
  36.  
  37.     return 0;   

不知道有没有哪里写错了, 等学的深一点了再回头来检查好了。反正log里面木有问题就是,哈哈。

#p#

17、指定初始化函数 designated initializer 的实际应用

  1. #import <Foundation/Foundation.h>   
  2.  
  3.     
  4.  
  5. @interface Tire : NSObject   
  6.  
  7.  {   
  8.  
  9.     float pressure;   
  10.  
  11.     float treadDepth;   
  12.  
  13.  }   
  14.  
  15.  
  16.  
  17.  - (id) initWithPressure: (float) pressure   
  18.  
  19.               treadDepth: (float) treadDepth;   
  20.  
  21.      
  22.  
  23.  - (id) initWithPressure: (float) pressure;   
  24.  
  25.     
  26.  
  27.  - (id) initWithTreadDepth: (float) treadDepth;   
  28.  
  29.     
  30.  
  31.  @end   
  32.  
  33.     
  34.  
  35.  @implementation Tire   
  36.  
  37. // 注意   
  38.  
  39. - (id) init   
  40.  
  41.  {   
  42.  
  43.      if (self = [self initWithPressure:34 treadDepth:20]){   
  44.  
  45.     }   
  46.  
  47.          
  48.  
  49.     return self;   
  50.  
  51.  }   
  52.  
  53.     
  54.  
  55. - (id) initWithPressure:(float) p treadDepth:(float) t   
  56.  
  57. {   
  58.  
  59.      if (self = [super init]){   
  60.  
  61.         pressure = p;   
  62.  
  63.         treadDepth = t;   
  64.  
  65.      }   
  66.  
  67.      return (self);   
  68.  
  69.  }   
  70.  
  71.      
  72.  
  73.  - (id) initWithPressure:(float) p   
  74.  
  75.  {   
  76.  
  77.      if (self = [self initWithPressure:p treadDepth:20]){   
  78.  
  79.     }   
  80.  
  81.      return (self);   
  82.  
  83. }   
  84.  
  85.     
  86.  
  87. - (id) initWithTreadDepth: (float) t   
  88.  
  89. {   
  90.  
  91.     if (self = [self initWithPressure:34 treadDepth:t]){   
  92.  
  93.    }   
  94.  
  95.      return (self);   
  96.  
  97.  }   
  98.  
  99.     
  100.  
  101.  - (NSString *) description   
  102.  
  103.  {   
  104.  
  105.    NSString *desc;   
  106.  
  107.     desc = [NSString stringWithFormat:@"Tire : Pressure : %.1f , TreadDepth : %.1f", pressure, treadDepth];   
  108.  
  109.     return (desc);   
  110.  
  111.  }   
  112.  
  113.     
  114.  
  115.  @end   
  116.  
  117.      
  118.  
  119.  @interface TireSub : Tire   
  120.  
  121. {   
  122.  
  123.     float sub1;   
  124.  
  125.     float sub2;   
  126.  
  127. }   
  128.  
  129.     
  130.  
  131.  @end   
  132.  
  133.      
  134.  
  135.  @implementation TireSub   
  136.  
  137.  // 注意子类的 init 方法   
  138.  
  139.  - (id) init   
  140.  
  141.  {   
  142.  
  143.      if (self = [super initWithPressure:34 treadDepth:20]){   
  144.  
  145.          sub1 = 59;   
  146.  
  147.         sub2 = 69;   
  148.  
  149.      }   
  150.  
  151.      return (self);   
  152.  
  153.  }   
  154.  
  155.      
  156.  
  157. - (NSString *) description   
  158.  
  159.  {   
  160.  
  161.      NSString *desc;   
  162.  
  163.      desc = [NSString stringWithFormat:@"Tire : Pressure : %.1f , TreadDepth : %.1f, Sub1 : %.1f, Sub2 : %.1f", pressure, treadDepth,sub1,sub2];   
  164.  
  165.      return (desc);   
  166.  
  167.  }   
  168.  
  169.         
  170.  
  171.  @end   
  172.  
  173.      
  174.  
  175.  int main(int argc, const char * argv[])   
  176.  
  177.  {   
  178.  
  179.      
  180.  
  181.      @autoreleasepool {   
  182.  
  183.              
  184.  
  185.          TireSub *tiresub = [[TireSub alloc] init];   
  186.  
  187.         NSLog(@"%@", tiresub);   
  188.  
  189.             
  190.  
  191.      }   
  192.  
  193.      return 0;   
  194.  
  195.  }  

18、Property 实例

  1. #import <Foundation/Foundation.h>   
  2.  
  3.     
  4.  
  5.  @interface MRProperty : NSObject   
  6.  
  7.  {   
  8.  
  9.      NSString *name ;   
  10.  
  11.     float address;   
  12.  
  13. }   
  14.  
  15.     
  16.  
  17. @property NSString *name;   
  18.  
  19. @property float num;   
  20.  
  21. @property(copy) NSString *string;              // for object type   
  22.  
  23.  @property(retain) NSMutableArray *array;       // for object type   
  24.  
  25.  @property NSString *secondName;   
  26.  
  27. @property(readonly) NSString *lover;   
  28.  
  29.      
  30.  
  31.     
  32.  
  33. - (id) initWithName: (NSString *) name   
  34.  
  35.            address: (float) num;   
  36.  
  37.     
  38.  
  39.  @end   
  40.  
  41.      
  42.  
  43.  @implementation MRProperty  // !  Incomplete implementation   
  44.  
  45.     
  46.  
  47.  @synthesize name;   
  48.  
  49.  @synthesize num;   
  50.  
  51.     
  52.  
  53. @synthesize string;   
  54.  
  55.  @synthesize array;   
  56.  
  57.      
  58.  
  59.  @synthesize secondName = second;   
  60.  
  61.  @synthesize lover;   
  62.  
  63.   
  64.  
  65.     
  66.  
  67. - (id) init   
  68.  
  69.  {   
  70.  
  71.     if ([self = self initWithName: @"ma" num: 40.0]) {   
  72.  
  73.    }   
  74.  
  75.    return (self);   
  76.  
  77.  }   
  78.  
  79.     
  80.  
  81.  - (id) initWithName: (NSString *) n num: (float) a   
  82.  
  83.  {   
  84.  
  85.     if (self = [super init]) {   
  86.  
  87.         name = [n copy];   
  88.  
  89.         num = a;   
  90.  
  91.             
  92.  
  93.        second = @"rong";   
  94.  
  95.        lover = @"zsl";   
  96.  
  97.     }   
  98.  
  99.    return (self);   
  100.  
  101.  }   
  102.  
  103.     
  104.  
  105.  @end   
  106.  
  107.     
  108.  
  109.  int main(int argc, const char * argv[])   
  110.  
  111.  {   
  112.  
  113.      
  114.  
  115.      @autoreleasepool {   
  116.  
  117.             
  118.  
  119.         MRProperty *property = [[MRProperty alloc] initWithName:@"ma" num:40];   
  120.  
  121.             
  122.  
  123.          property.string = @"Hi, my love!~";   
  124.  
  125.              
  126.  
  127.         NSLog(@"name is %@ ; num is %.1f ; string is %@.", property.name, property.num, property.string);   
  128.  
  129.          NSLog(@"my second name is : %@", property.secondName);   
  130.  
  131.              
  132.  
  133.         NSLog(@"my lover is : %@", property.lover);   
  134.  
  135.     }   
  136.  
  137.      return 0;   
  138.  
  139.  }  

19、category   (类别)

感觉需要多用才能更明白一点。。。

 

20、protocol (协议)

我把它理解为 java里面的接口,在定义类时声明需要实现哪些接口。(⊙o⊙)…不知道对伐。哎呦,为啥我觉得java里面的接口更好理解呢?

protocol的声明示例如下:

  1. @protocol Panel <NSObject>   
  2.  
  3.  // 必须实现   
  4.  
  5. - (id) create;   
  6.  
  7.  // 可选   
  8.  
  9.  @optional   
  10.  
  11.  - (void) drawCicle;   
  12.  
  13. - (void) drawDoted;   
  14.  
  15.  - (void) drawRect;   
  16.  
  17. // 必须实现   
  18.  
  19.  @required   
  20.  
  21.  - (void) clearPanel;   
  22.  
  23.     
  24.  
  25.  @end  

#p#

protocol的使用示例如下:

 

  1. #import <Foundation/Foundation.h>   
  2.  
  3. #import "Panel.h"   
  4.  
  5.    
  6.  
  7. @interface Engine : NSObject <NSCopying,NSCoding>   
  8.  
  9. @end  

protocol的使用示例如下:

  1. // 跟在id之后,要求对象遵守指定的协议   
  2.  
  3.  - (void) setObjectValue: (id<NSCopying>) obj;   
  4.  
  5. // 用协议修饰方法的参数   
  6.  
  7.  - (void) draft: (Person<BaseballPlayer> *person);  

21、block (块)

  1. <SPAN style="LINE-HEIGHT: 1.5; FONT-SIZE: 9pt">int (^square_block)(int number) =</SPAN> ^(int number) {return (number * number);};   
  2.  
  3.        int result = square_block(5);   
  4.  
  5.       NSLog(@"%d",result);   
  6.  
  7.         
  8.  
  9.        typedef double (^MKSampleMultiplyBlockRef)(double a, double b);     
  10.  
  11.       MKSampleMultiplyBlockRef multiply = ^(double a,double b){ return a * b;};   
  12.  
  13.         MKSampleMultiplyBlockRef add = ^(double a,double b){ return a + b;};   
  14.  
  15.           
  16.  
  17.        double a = 20, b = 40;   
  18.  
  19.        __block double c = 3;   
  20.  
  21.       MKSampleMultiplyBlockRef multiply2 = ^(double a, double b) {c = a * b;};   
  22.  
  23.        // 如果不声明 __block ,则编译时会出错。   
  24.  
  25.       // 没有长度的可变数组 和 没有长度的结构体 无法被声明为 __block 类型   
  26.  
  27.       NSLog(@"%f",multiply(a,b));   
  28.  
  29.        NSLog(@"%f",add(a,b));  

block可以定义很多函数块,唯一的限制是这些函数块能拥有的参数只能是定义时的形参,不过它可以使用的变量的范围却很广。

全局变量、全局函数、封闭范围内的参数、函数级别的__block变量、封闭范围内的非静态变量会被获取为常量、objective-c的实例变量、代码块内部的本地变量

22、并发性

// 又是需要深究的一章

23、文件读取和写入

属性列表类,包括:NSArray、NSDirectory、NSString、NSNumber、NSDate、NSData

  1. NSDate *date = [NSDate date];   
  2.  
  3.        NSLog(@"today is %@", date);   
  4.  
  5.             
  6.  
  7.         NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow: -(24 * 60 * 60)];   
  8.  
  9.          NSLog(@"yesterday is %@", yesterday);   
  10.  
  11.              
  12.  
  13.         const char *string = "hi, there, this is a c string!";   
  14.  
  15.         NSData *data = [NSData dataWithBytes:string length: strlen(string) + 1];   
  16.  
  17.         NSLog(@"data is %@", data);   
  18.  
  19.              
  20.  
  21.         NSLog(@"%d byte string is '%s'", [data length], [data bytes]);   
  22.  
  23.            
  24.  
  25.         NSArray *phrase;   
  26.  
  27.         phrase = [NSArray arrayWithObjects:@"l", @"seem", @"to",@"be", @"very", @"sad" , nil];   
  28.  
  29.          [phrase writeToFile:@"/Users/marong/Documents/test.txt" atomically:YES];   
  30.  
  31.          // atomically 是否先写入缓冲区,(写入成功后再替换原文件,可避免写入失败损坏源文件,但须双倍磁盘空间)   
  32.  
  33.          NSArray *phrase2;   
  34.  
  35.          phrase2 = [NSArray arrayWithContentsOfFile:@"/Users/marong/Documents/test.txt"];   
  36.  
  37.          NSLog(@"%@", phrase2);   
  38.  
  39.      
  40.  
  41.  // 2013-07-08 12:28:09.181 File[936:303] today is 2013-07-08 04:28:09 +0000   
  42.  
  43.  // 2013-07-08 12:28:09.181 File[936:303] yesterday is 2013-07-07 04:28:09 +0000   
  44.  
  45.  // 2013-07-08 12:28:09.182 File[936:303] data is <68692c20 74686572 652c2074 68697320 69732061 20632073 7472696e 672100>   
  46.  
  47.  // 2013-07-08 12:28:09.182 File[936:303] 31 byte string is 'hi, there, this is a c string!'   
  48.  
  49.  // 2013-07-08 12:28:09.183 File[936:303] (   
  50.  
  51.      l,   
  52.  
  53.     seem,   
  54.  
  55.      to,   
  56.  
  57.      be,   
  58.  
  59.      very,   
  60.  
  61.     sad   
  62.  

24、通过NSCoding协议编码和解码对象

// 表示又不太明白,脑子有点糊里糊涂的感觉了

 

25、提供逻辑上有意义的值,自定制空值:

-setNilValueForKey:

 

26、处理未定义的键(可重写默认方法)

-valueForUndefinedKey:

-setValue:forUndefinedKey;

 

27、简单键值操作示例

 

  1.  Car *car;   
  2.  
  3.          car = [[Car alloc] initWithName:@"car1" modelYear:1988 numberOfDoors:1 mileage:1980.0];   
  4.  
  5.             
  6.  
  7.         NSLog(@"%@", car);   
  8.  
  9.             
  10.  
  11.         NSLog(@"%@", [car valueForKey:@"name"]);   
  12.  
  13.         // valueForKey : 查找 -key 或 -isKey 命名的get方法,入不存在,则查找 对象内部名为 _key 或key 的实例变量。   
  14.  
  15.        // c或c++中无法进行该操作   
  16.  
  17.              
  18.  
  19.        [car setValue:@"Harold" forKey:@"name"];   
  20.  
  21.          [car setValue: [NSNumber numberWithInt: 1988]   
  22.  
  23.                forKey:@"modelYear"];   
  24.  
  25.              
  26.  
  27.         NSLog(@"%@", car);   
  28.  
  29.             
  30.  
  31.        [car setValue: [NSNumber numberWithFloat: 29.98]   
  32.  
  33.                forKeyPath:@"engine.horsepower"];   
  34.  
  35.              
  36.  
  37.         NSLog(@"%@", [car valueForKeyPath:@"engine.horsepower"]);   
  38.  
  39.         NSLog(@"%@", [car valueForKeyPath:@"tires"]);   
  40.  
  41.         // 如果路径中含有一个数组属性,则该键路径的其余部分将被发送给数组的每个对象   
  42.  
  43.             
  44.  
  45.         NSNumber *num = [car valueForKeyPath:@"tires.@count"];   
  46.  
  47.         NSLog(@"car has %d tires", num);   
  48.  
  49.        // @count, @blah, @interface,@avg,@sum,@min,@max,@distinctUnionOfObjects (改变所有属性)   
  50.  
  51.    
  52.  
  53.  //Car-Value-Coding[2680:303] car1 , a 1988 1 1980.0 has 4 tires.   
  54.  
  55.  //Car-Value-Coding[2680:303] car1   
  56.  
  57.  //Car-Value-Coding[2680:303] Harold , a 1988 1 1980.0 has 4 tires.   
  58.  
  59.  //Car-Value-Coding[2680:303] 29.98   
  60.  
  61.  //Car-Value-Coding[2680:303] (   
  62.  
  63. //    tires0,   
  64.  
  65.  //    tires1,   
  66.  
  67.  //    tires2,   
  68.  
  69. //    tires3   
  70.  
  71.  //)   
  72.  
  73.  //Car-Value-Coding[2680:303] car has 1223 tires  

28、NSPredicate:数组运算符 -- の,需要深入理解


29、NSPredicate:SELF

  1. <STRONG> NSArray *array = [NSArray arrayWithObjects:@"marong1", @"marong2", @"marong3", nil];   
  2.  
  3.        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF IN {'Herbie', 'marong1', 'marong2'}"];   
  4.  
  5.             
  6.  
  7.         NSArray *result;   
  8.  
  9.          result = [array filteredArrayUsingPredicate:predicate];   
  10.  
  11.             
  12.  
  13.         NSLog(@"%@", result);   
  14.  
  15.      
  16.  
  17.  //NSPredicate[3008:303] (   
  18.  
  19.  //    marong1,   
  20.  
  21.  //    marong2   
  22.  
  23.  //) </STRONG>  

31、@synchronized(object){ // critical section}  

// 确保不同线程会连续访问临界区的代码 (mark,关于并发性即多线程问题,不太明

当object为nil时,静态分析器将会发出警告。

@synchronize(mutex,atomic) // 系统自动生成,保证getter和setter方法互斥

31、新手注意事项大集合

    1》id类型:在Objective-C 中,id 类型是一个独特的数据类型。在概念上,类似Java 的Object 类,可以转换为任何数据类型。换句话说,id 类型的变量可以存放任何数据类型的对象。在内部处理上,这种类型被定义为指向对象的指针,实际上是一个指向这种对象的实例变量的指针。(参 考:http://blog.csdn.net/lonelyroamer/article/details/7711895)

    2》在类的interface中,没有参数的方法后面不加冒号;

    3》[super 方法名: 参数];   // 在override superclass中的某个方法时,需要在方法***面加上这句调用superclass中的该方法。

    4》self = [super init]    // 相关解释如下所示:

     5》继承&复合:inheritance & composition:is & has

     6》accessors :存取器

责任编辑:张叶青 来源: 开源社区
相关推荐

2015-06-08 10:02:40

swiftOC兼容

2011-07-22 15:42:39

Objective-C UIView 内存

2011-08-04 14:58:37

Objective-C Cocoa NSString

2011-05-11 14:06:49

Objective-C

2011-07-25 10:03:06

Objective-C 委托

2011-08-05 14:03:39

Objective-C 对象 模板

2011-07-25 10:30:41

Objective-C Xcode 重构

2011-07-25 11:02:29

Objective-C Xcode 标签

2011-07-25 10:14:13

Objective-C Xcode

2011-07-06 14:41:34

Objective-C

2011-08-15 17:06:01

Objective-CNSLog

2011-08-16 10:23:04

Objective-CNSAutoreleaXcode常用键

2011-08-10 18:07:29

Objective-C反射

2013-03-27 12:54:00

iOS开发Objective-C

2011-05-11 15:58:34

Objective-C

2013-06-20 10:40:32

Objective-C实现截图

2011-05-11 11:20:26

Objective-C

2011-08-16 13:34:23

Objective-C归档

2011-08-04 10:57:33

Objective-C C语言 BOOL

2011-07-28 15:11:23

iOS Objective-
点赞
收藏

51CTO技术栈公众号