标签:
1.错误域Error Domain
NSMachErrorDomain:系统内核错误
NSPOSIXErrorDomain:系统错误
NSOSStatusErrorDomian:MacOS9之前的错误或者Carbon框架错误
NSCocoaErrorDomain:cocoa框架错误
2.本地化错误描述
(1)NSUnderlyingErrorKey
NSDictionary *userInfo = [error userInfo];
NSString *errorDesc = nil;
//检查有没有"NSUnderlyingErrorKey"可供使用
if(userInfo && [userInfo objectForKey:NSUnderlyingErrorKey]){
NSError *underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey];
if(underlyingError){
errorDesc = [underlyingError localizedDescription];
}
else{
errorDesc = [error localizedDescription];
}
}
else{
errorDesc = [error localizedDescription];
}
(2)localized Description
NSError *errorInfo = nil;
//假设在操作系统的根目录上放一个"test.rtf"文件,strTest拿到@"/test.rf"的内容
NSString *strTest = [NSString stringWithContentsOfFile:@"/test.rf"
encoding:NSUTF8StringEncoding
ettor:&errorInfo];
if(!strTest){
if(!errorInfo){
NSLog(@"An error occurred: %@" , [errorInfo localizedDescription]);
}else{
NSLog(@"An unknow error occurred" );
}
}
3.输出当前的函数
%s __FUNCTION__
4.单例
share*****
default*****
5.ARC
weak和strong代替assign.retain.copy
6.KVC
valueForKeyPath 取
setValue: forkey: 设置
7.KVO
[self addObserver:self
forKeyPath:@"datasrc"
options:*****
context:@"testContent"];
标签:
原文地址:http://www.cnblogs.com/zhongxuan/p/5161980.html