代碼塊就至關於C語言中一個函數同樣程序員
//
// main.m
// DaiMaKuai
//
// Created by 非凡程序員 on 15/5/28.
// Copyright (c) 2015年 非凡程序員. All rights reserved.
//app
#import <Foundation/Foundation.h>函數
int main(int argc, const char * argv[]) {
@autoreleasepool {spa
int i=7;排序
//代碼塊格式以下:
int (^chengFa)(int,int) = ^(int num1,int num2) {return num1*num2;};
int aa=chengFa(4,5);
NSLog(@"%i",aa); ci
// 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());
// 字符串
};
string
//首字母排序(數字優先)
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));it
haha cc= ^(double c,double f)
{
return c +f;
};
NSLog(@"%.2f", cc(1.2,2.2));
}
return 0;
}io
/*--------------------字符串----------------------------*/
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);