Laugh grammar, grammar sugar----literal

Source: Internet
Author: User

1. Quickly create NSNumber objects
NSNumber *number1 = @20; @ + constant
int a = 20;
NSNumber *number2 = @ (a); @ + (variable)
2. Quickly create a string object that converts the C-language string constant to OC
NSString *str1 = @ "Frank";
3. Quickly create Nsarry objects
Nsarray *arr1 = @[@ "AA", @ "Hu", @ "Ty", @ "FD"];
4. Quickly create Nsmutablearry objects
Nsmutablearray *ARR2 = [@[@ "DG", @ "Ji", @ "GT", @ "FG"] mutablecopy];
5. Quickly remove elements from the array according to subscript
NSString *str2 = arr1[0];
NSString *STR3 = arr2[3];
6. Quickly create Nsdictionary Dictionary objects
Nsdictionary *dic = @{@ "name": @ "Frank" @ "Age": @ "+" @ "gender": @ "man"};
7. Quickly create Nsmutabledictionary objects
Nsmutabledictionary *dic1 = [@{@ "name": @ "Frank" @ "Age": @ "+" @ "gender": @ "man"} Mutablecopy];
8. Quickly remove the corresponding value according to key
NSString *STR4 = dic[@ "name"];
NSString *srt5 = dic1[@ "Age"];

2. Converting NSNumber Data Objects to basic data types
NSNumber *number1 = @20;
NSNumber *number2 [email protected];
NSNumber *number3 = @NO;
NSNumber *number4 = @ ' m ';
int newNumber1 = [Number1 intvalue];
NSLog (@ "%d", newNumber1);
float NewNumber2 = [number2 floatvalue];
NSLog (@ "%.1f", newNumber2);
BOOL NewNumber3 = [Number3 boolvalue];
NSLog (@ "%d", newNumber3);
char newNumber4 = [Number4 charvalue];
NSLog (@ "%c", newNumber4);


Laugh grammar, grammar sugar----literal

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.