OC Simple grammar grammar sugar

Source: Internet
Author: User

1.方法与顺序无关  

      2.枚举绑定数据类型   enum {        ObjectiveC,        Java,        Ruby,        Python,        Erlang   };   typedef NSUInteger Language;         3. 属性不用写@synthesize         4.语法简化   4.1 NSNumber   NSNumber *value;   value = @12345;   value = @123.45f;   value = @123.45;   value = @YES;         4.2 NSArray   NSArray *array;   array = @[];                //空数组   array = @[ a ];           //一个对象的数组   array = @[ a, b, c ];  //多个对象的数组         4.3 NSDictionary   NSDictionary *dict;   dict = @{};      //空字典   dict = @{ k1 : o1 };      //包含一个键值对的字典   dict = @{ k1 : o1, k2 : o2, k3 : o3 };  //包含多个键值对的字典         注:对可变的容器,可以用:   NSMutableArray *mutablePlanets = [@[       @ "Mercury" , @ "Venus" , @ "Earth" ,       @ "Mars" , @ "Jupiter" , @ "Saturn" ,       @ "Uranus" , @ "Neptune"   ] mutableCopy];               5.对象下标   可以通过下标方式存取数组和字典的数据,类似C语言结构         5.1 NSArray   NSArray *array = @[ a, b, c ];   id obj = array[i];      //通过下标方式获取数组对象,替换原有写法:array objectAtIndex:i];   array[i] = newObj;      //也可以直接为数组对象赋值。替换原有写法:[array replaceObjectAtIndex:i withObject:newObj];         5.2 NSDictionary   NSDictionary *dict = @{ k1 : o1, k2 : o2, k3 : o3 };   id obj = dict[k2];      //获取o2对象,替换原有写法:[dic objectForKey:k2];   dic[k2] = newObj;   //重新为键为k2的对象赋值,替换原有写法:[dic setObject:newObj forKey:k2]         6.小结   @ # nsnumbers   @{} dictionaries   @“” strings   @[] arrays   @() expressions

OC Simple grammar grammar sugar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.