#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. webpack2 详解

    1.安装 npm install webpack -g npm install webpack -save-dev 2.编辑配置文件 // 引入 path var path=require('path ...

  2. Java线程池 ExecutorService

    一.ExecutorService介绍 ExecutorService是Java中对线程池定义的一个接口,它java.util.concurrent包中,在这个接口中定义了和后台任务执行相关的方法:  ...

  3. c程序设计语言第一章5

    练习1.20请编写程序d e t a b

  4. oracle 导出数据字典

    一.查看当前用户下表名,及表名的备注 select * from user_tab_comments where table_name like 'T_ONLINE%' 二.查询数据字典 -- 1. ...

  5. No Memory Alignment with GCC

    attribute method: #include <stdio.h> struct packed { char a; int b; } __attribute__((packed)); ...

  6. eclipse配置android

    先在eclipse中安装ADT插件,install内点击add,name:ADT, URL:http://dl-ssl.google.com/android/eclipse/ 之后直接finish就好 ...

  7. debian apt-get工作的原理

    1 apt-get update apt-get update并没有将远程仓库的包都下载到本地,而是通过访问远程仓库创建或者更新了远程仓库的本地索引,索引文件放在/var/lib/apt/lists目 ...

  8. 织梦dedecms标签调用集合,绝对是仿站必备利器

    今天分享下整理了织梦dedecms标签调用集合,绝对是仿站必备利器啊,觉得有用就转走吧!温馨小提示:CTRL+F 搜索你需要的标签名,就可以方便找到:织梦dedecms标签调用集合-首页标签:网站导航 ...

  9. 常用: JS 获取浏览器窗口大小

    // 获取窗口宽度 if (windows.innerWidth) winWidth = windows.innerWidth; else if ((document.body) && ...

  10. Android Studio 3.0.1模拟器启动报错Emulator: glClear:466 GL err 0x502

    启动模拟器时,报了一大堆以上错误 启动起来之后, Emulator的画面没有正常显示, 点击鼠标会闪烁, 有时还会上下颠倒 有可能是驱动版本太低不支持一些特性,因此就下载个驱动精灵.升级了显卡驱动,结 ...