标签:
//类名的反射 NSString *str=@“Person”; Class class=NSClassFromString(str); Person *person=[[class alloc]init]; //类转换为字符串 NSString *name=NSStringFromClass([Person clas]); //方法的反射 NSString *method=@“test”; SEL selector=NSSelectorFromString(method); [person performSelector:selector]; //将方法转换为字符串 NSString *selectorname=NSStringFromSelector(selector);
NSString *str1=[[NSString alloc]initWithFormat:@“age is 10”]; NSString *str2=[str1 copy]; //copy出来的还是原来的对象,没有产生新的对象
NSString *str=[[NSString alloc]initWithFormat:@“age is 10”]; NSMutableString *str1=[str MutableCopy]; //产生了新的对象,因此是深度复制
OC——Foundation—常用的类(5)——NSObject和反射、copy语法
标签:
原文地址:http://www.cnblogs.com/hqzxbb/p/4425072.html