代码块就相当于C语言中一个函数一样
//
// main.m
// DaiMaKuai
//
// Created by 非凡程序员 on 15/5/28.
// Copyright (c) 2015年 非凡程序员. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
int i=7;
//代码块格式如下:
int (^chengFa)(int,int) = ^(int num1,int num2) {return num1*num2;};
int aa=chengFa(4,5);
NSLog(@"%i",aa);
// NSArray * test = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"];
//
// NSArray * (^zhuanHua)(void) = ^(void)
// {
//
// NSMutableArray * zhuan = [NSMutableArray arrayWithCapacity:10];
//
// for( int i = 9 ; i >= 0 ; i-- )
// {
// [zhuan addObject: test[i]];
// }
// return zhuan;
// };
//
// NSLog(@"%@,zhuanHua());
//
};
//首字母排序(数字优先)
NSArray *test2=[NSArray arrayWithObjects:@"asdsf",@"bfgdg",@"dadgre",@"33",@"2",@"230", nil];
NSArray *paiXu=[test2 sortedArrayUsingComparator:^(NSString *aa1,NSString *aa2)
{
return [aa1 compare:aa2];
}];
NSLog(@"%@,paiXu);
//haha相当于一个类的名字,dd和cc相当于一个可调用到方法
typedef double (^haha)(double c,double f);
haha dd= ^(double c,double f)
{
return c * f;
};
NSLog(@"%.2f", dd(1.2,2.2));
haha cc= ^(double c,double f)
{
return c +f;
};
NSLog(@"%.2f", cc(1.2,2.2));
}
return 0;
}
/*--------------------字符串----------------------------*/
NSMutableString *pp2=[NSMutableString stringWithCapacity:1]; //可变字符串
[pp2 appendString:@"dsfsdfsg"];
[pp2 appendString:@"1111"];//增加字符内容
NSLog(@%@,pp2);
NSRange a = NSMakeRange(2, 3);
NSRange strRange = [pp2 rangeOfString:@"1111"];//查找内容
[pp2 replaceCharactersInRange:strRange withString:@"ds"]; // 替换
// [pp2 deleteCharactersInRange:strRange];//删除内容
NSLog(@%@,pp2);