IOS高级开发~Runtime(二)
#import <Foundation/Foundation.h> @interface CustomClass : NSObject
{
NSString *varTest1;
NSString *varTest2;
NSString *varTest3;
}
@property(nonatomic,strong) NSString *varTest1;
@property(nonatomic,strong) NSString *varTest2;
@property(nonatomic,strong) NSString *varTest3;
@interface CustomOtherClass : NSObject
{
int varTest2;
}
-(void)fun2;
@interface ViewController (){
float myFloat;
CustomClass *allobj;
}
/**
获取一个类所有方法
*/
-(void)getClassAllMethod{
u_int count;
Method *methods = class_copyMethodList([ViewController class], &count);
for (int i = 0; i < count; i++) {
SEL name = method_getName(methods[i]);
NSString *strName = [NSString stringWithCString:sel_getName(name) encoding:NSUTF8StringEncoding];
NSLog(@"strName:%@",strName);
}
}
/**
获取一个类的所有属性
*/
-(void)propertyNameList{
u_int count;
objc_property_t *properties = class_copyPropertyList([UIViewController class], &count);
for (int i = 0; i < count; i++) {
const char* propertyName = property_getName(properties[i]);
NSString *strName = [NSString stringWithCString:propertyName encoding:NSUTF8StringEncoding];
NSLog(@"strName:%@",strName);
}
}
/**
获取全局变量的值
*/
-(void)getInstanceVar{
float myFloatValue;
object_getInstanceVariable(self, "myFloat", (void*)&myFloatValue);
NSLog(@"myFloatValue:%f",myFloatValue);
}
/**
判断某一个类的某一个属性的类型
*/
-(void)getVarType{
CustomClass *obj = [CustomClass new];
Ivar var = class_getInstanceVariable(object_getClass(obj), "varTest1");
const char*typeEdcoding = ivar_getTypeEncoding(var);
NSString *strName = [NSString stringWithCString:typeEdcoding encoding:NSUTF8StringEncoding];
if ([strName hasPrefix:@"@"]) {
NSLog(@"handle class case");
}else if ([strName hasPrefix:@"i"]){
NSLog(@"handle int case");
}else if ([strName hasPrefix:@"f"]){
NSLog(@"handle float case");
}else{
}
}
IOS高级开发~Runtime(二)的更多相关文章
- IOS 高级开发 runtime(二)
二.移魂大法 使用runtime还可以交换两个函数.先贴上代码和执行结果. #import <Foundation/Foundation.h> @interface DZLPerson : ...
- IOS高级开发 runtime(一)
一. 简介 IOS 开发中灵活使用runtime 会提高我们的程序性能和开发速度.要想使用runtime,首先要引入系统的头文件. <span style="font-size:18p ...
- iOS 高级开发 runtime(三)
三 .动态添加方法 我们可以通过runtime动态地添加方法.那么到底啥叫动态添加方法呢?动态添加方法就是当我们程序运行时才知道我们应该调用哪个方法.我们首先需要了解这一点,当我们编写完一段代码后,我 ...
- (转发)IOS高级开发~Runtime(二)
一些公用类: @interface ClassCustomClass :NSObject{ NSString *varTest1; NSString *varTest2; NSString *varT ...
- (转发)IOS高级开发~Runtime(四)
用C代替OC: #import <objc/runtime.h> #import <objc/message.h> #import <stdio.h> extern ...
- (转发)IOS高级开发~Runtime(三)
11.系统类的方法实现部分替换 - (void) methodExchange { Method m1 = class_getInstanceMethod([NSStringclass],@selec ...
- (转发)IOS高级开发~Runtime(一)
IOS高级开发-Runtime(一) IOS高级开发-Runtime(二) IOS高级开发-Runtime(三) IOS高级开发-Runtime(四) 一些公用类: @interface Custom ...
- iOS蓝牙开发(二)蓝牙相关基础知识
原文链接: http://liuyanwei.jumppo.com/2015/07/17/ios-BLE-1.html iOS蓝牙开发(一)蓝牙相关基础知识: 蓝牙常见名称和缩写 MFI ====== ...
- IOS高级开发之多线程(四)NSOperation
1.什么是NSOperation,NSOperationQueue? NSOperation是一个抽象的基类,表示一个独立的计算单元,可以为子类提供有用且线程安全的建立状态,优先级,依赖和取消等操作. ...
随机推荐
- Classification and logistic regression
logistic 回归 1.问题: 在上面讨论回归问题时.讨论的结果都是连续类型.但假设要求做分类呢?即讨论结果为离散型的值. 2.解答: 假设: 当中: g(z)的图形例如以下: 由此可知:当hθ( ...
- [ACM] POJ 3253 Fence Repair (Huffman树思想,优先队列)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25274 Accepted: 8131 Des ...
- nginx 配置nginx.conf,负载均衡,逻辑分流
nginx 最重要的配置文件nginx.conf: 一般的配置我不做解释,网上到处都是,主要对主要的几点进行注释(如下) worker_processes ; error_log /data/logs ...
- C#语言 ArrayList集合
- DICOM-RT:放疗流程与參与角色
背景: 放疗是一个复杂的过程,同一时候须要肿瘤医师.模拟定位技师.剂量师.物理师.治疗技师.护士等多重角色參与.总体流程涉及到成像系统.定位系统.计划系统.治疗系统.质控QA系统.信息管理系统等多个独 ...
- Android(Linux)模拟按键、触摸屏等事件
前提: 在我们应用程序或者在写Android自己主动化測试时候经常会须要模拟实体按键,来给我们做測试用.这也是我要整理的目的. 基本的涉及的是Linux Input Event事件. 下面的样例基于A ...
- error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
头文件函数声明少了“:(分号)”
- C语言的一些特殊使用方法————————【Badboy】
一:特殊的字符串宏 [cpp] #define A(x) T_##x #define B(x) #@x #define C(x) #x 我们如果x=1, 则上面的宏定义会被解释成下面的样子 A(1)- ...
- 【Java】Java代码经典错误清单
一.String 对照 == 和 equals.详细描写叙述例如以下 "=="操作符的作用 1)用于基本数据类型的比較,例如以下: byte(字节) 8 -128 - 127 0 ...
- C/C++ 操作符优先级
不能光转贴,有空要熟悉之后,要写点心得.现在发现 . 的优先级确实很高. C: Precedence Operator Description Associativity 1 ++ -- Suffix ...