#pragma mark-block Syntax
NSLog(@ "========block method 1===========");
[Students sortusingcomparator: ^nscomparisonresult(ID obj1, ID obj2) {
Student *stu1 = (Student *) obj1; the obj1 here is the Student type.
Student *stu2 = (Student *) obj2;
NSLog (@ "%ld", [STU1. Name COMPARE:STU2. Name]);
return [STU1. Name COMPARE:STU2. Name];
}];
NSLog(@ "======= method 2==========");
nscomparator sortbyname = ^Nscomparisonresult (Student *obj1,Student *obj2)
{
return [Obj1. Name compare:obj2. Name];
};
[Students Sortusingcomparator:sortbyname];
NSLog (@ "%@", students);
// age
NSLog(@ "=========age=========");
[Students sortusingcomparator:^nscomparisonresult (Student *obj1, Student *obj2) {
if (obj1. Age > Obj2. Age ) {
return nsordereddescending;
}Else if (obj1. Age < Obj2. Age )
{
return nsorderedascending;
}
return nsorderedsame;
}];
NSLog (@ "%@", students);
// study No.
NSLog(@ "==========num=========");
[Students sortusingcomparator:^nscomparisonresult (Student *obj1, Student *obj2) {
if (obj1. num > Obj2. num) {
return nsordereddescending;
}Else if (obj1. Num < Obj2. num)
{
return nsorderedascending;
}
return nsorderedsame;
}];
NSLog (@ "%@", students);
#pragma mark- lol grammar
laugh Grammar Get string
NSString *str = [[NSString alloc] initwithutf8string:" convert C language to OC string " ];
nsstring *str1 = @ " laughing and laughing Grammar ";
laugh Grammar Get array
Nsarray *arr = [[nsarray alloc] initwithobjects:str,str1, Nil];
Nsarray *arr1 = @[str,str1];
[Arr Objectatindex:0];
ARR[0];
NSLog (@ "%@", arr[1]);
Laugh Grammar get dictionary
NSLog(@ "======= get Dictionary ========");
Nsdictionary *dic = [[Nsdictionary alloc] initwithobjectsandkeys:str,@ "str", str1,@ "str1", nil];
nsdictionary *dic1 = @{@ "str": str,@ "str1": str1};
NSLog (@ "%@", Dic1);
Laugh grammar get value by key
[Dic1 Valueforkey:@ "str1"];
NSLog (@ "%@", dic1[@ "str1"]);
Laugh grammar Get value object
NSNumber *NUM10 = [NSNumber numberwithint:ten];
@10;
@1.2;
NSLog (@ "%@", NUM10);
//Laughter grammar created , are immutable .
}
return 0;
}
Objective-c block method and laughter grammar