1.NSMutableDictionary傳nil
setObject:forKey:崩潰
setValue:forKey:覆蓋為nil
dic[@"xx"] = nil語法糖覆蓋為nil
2.使用SDWebImage保存圖片到本地
[[SDImageCache sharedImageCache]storeImage:image forKey:imageUrl];
3.color轉(zhuǎn)換成UIImage
- (UIImage *)createImageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
4.測(cè)試程序運(yùn)行耗時(shí)
NSDate* tmpStartData = [NSDate date];
//You code here...
double deltaTime = [[NSDate date] timeIntervalSinceDate:tmpStartData];
NSLog(@">>>>>>>>>>cost time = %f ms", deltaTime*1000);
5.字符串?dāng)U展名處理
//拓展名處理
void exetension(){
NSString *str=@"/User/MJ/test.txt";
//判斷拓展名
NSLog(@"拓展名:%@",[str pathExtension]);//拓展名:txt
//刪掉拓展名
NSLog(@"%@",[str stringByDeletingPathExtension]);///User/MJ/test
//在字符串后面拼接一個(gè)拓展名
NSLog(@"%@",[@"abc"stringByAppendingPathExtension:@"mp3"]);//abc.mp3
}
6.const含義
I 常量指針
// 初始化之后不能賦值,指向的對(duì)象可以是任意對(duì)象,對(duì)象可變。
NSString * const pt1;
II 指向常量的指針
// 初始化之后可以賦值,即指向別的常量,指針本身的值可以修改,指向的值不能修改
const NSString * pt2;
III 指向常量的常量指針
const NSString * const pt3;