#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(二)的更多相关文章

  1. IOS 高级开发 runtime(二)

    二.移魂大法 使用runtime还可以交换两个函数.先贴上代码和执行结果. #import <Foundation/Foundation.h> @interface DZLPerson : ...

  2. IOS高级开发 runtime(一)

    一. 简介 IOS 开发中灵活使用runtime 会提高我们的程序性能和开发速度.要想使用runtime,首先要引入系统的头文件. <span style="font-size:18p ...

  3. iOS 高级开发 runtime(三)

    三 .动态添加方法 我们可以通过runtime动态地添加方法.那么到底啥叫动态添加方法呢?动态添加方法就是当我们程序运行时才知道我们应该调用哪个方法.我们首先需要了解这一点,当我们编写完一段代码后,我 ...

  4. (转发)IOS高级开发~Runtime(二)

    一些公用类: @interface ClassCustomClass :NSObject{ NSString *varTest1; NSString *varTest2; NSString *varT ...

  5. (转发)IOS高级开发~Runtime(四)

    用C代替OC: #import <objc/runtime.h> #import <objc/message.h> #import <stdio.h> extern ...

  6. (转发)IOS高级开发~Runtime(三)

    11.系统类的方法实现部分替换 - (void) methodExchange { Method m1 = class_getInstanceMethod([NSStringclass],@selec ...

  7. (转发)IOS高级开发~Runtime(一)

    IOS高级开发-Runtime(一) IOS高级开发-Runtime(二) IOS高级开发-Runtime(三) IOS高级开发-Runtime(四) 一些公用类: @interface Custom ...

  8. iOS蓝牙开发(二)蓝牙相关基础知识

    原文链接: http://liuyanwei.jumppo.com/2015/07/17/ios-BLE-1.html iOS蓝牙开发(一)蓝牙相关基础知识: 蓝牙常见名称和缩写 MFI ====== ...

  9. IOS高级开发之多线程(四)NSOperation

    1.什么是NSOperation,NSOperationQueue? NSOperation是一个抽象的基类,表示一个独立的计算单元,可以为子类提供有用且线程安全的建立状态,优先级,依赖和取消等操作. ...

随机推荐

  1. PS 图层后面有索引两字怎么办

    ps中图层后面有索引两字的怎么把它拖进别的图中?或怎么把索引去掉? 悬赏分:0 | 解决时间:2010-11-5 08:58 | 提问者:jk500pk 最佳答案 图像--模式 把索引颜色模式改成RG ...

  2. WheelView实现省市区三级联动(数据库实现版本号附带完整SQL及数据)

    近期在实现收货地址功能,用到了省市区三级联动效果,网上找到一般都是xml或json.数据源陈旧改动麻烦.改动了一下使用数据库方式实现了一下 数据源解决.因为数据量比較大通过初始化批量运行SQL的方式不 ...

  3. Log4cpp 使用手册

    参考资料: log4cpp 配置 与 使用http://www.cnblogs.com/welkinwalker/archive/2011/06/23/2088197.html 便利的开发工具-log ...

  4. struts.xml中为什么加上<constant name="struts.devMode" value="true" />就出错

    严重: Exception starting filter struts2 java.lang.NullPointerException at com.opensymphony.xwork2.util ...

  5. C#语言 数组

  6. Elasticsearch 学习笔记 Elasticsearch及Elasticsearch head安装配置

    一.安装与配置 1.到官网下载Elasticsearch,https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6. ...

  7. ActiveMQ(四) 转

    package pfs.y2017.m11.mq.activemq.demo04; import javax.jms.Connection; import javax.jms.ConnectionFa ...

  8. (转)OutOfMemory时抓取heap 快照

    转自:https://testerhome.com/topics/579 首先说一下,在程序没有崩溃的时候如何抓取heap快照.这个大家应该都知道,在ddms中自带此功能.   见上图首先我们选中一个 ...

  9. Golang-interface(二 接口与nil)

    github: https://github.com/ZhangzheBJUT/blog/blob/master/nil.md 一 接口与nil 前面解说了go语言中接口的基本用法,以下将说一说nil ...

  10. HDU 6086 Rikka with String AC自动机 + DP

    Rikka with String Problem Description As we know, Rikka is poor at math. Yuta is worrying about this ...