#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. 源码编译安装php

    原文:https://klionsec.github.io/2017/11/23/phpsec/#menu After compile install php 5.3.1, I can not fin ...

  2. webrtc初探

    0.闲来无事,想研究webrtc,看了一些网上的文章之后,觉得谬误较多,以讹传讹的比较多,自己试验了一把,记录一下. 官网的写的教程在实践中也觉得不用那么复杂,有种落伍与繁冗的感觉. 1.我想看的是w ...

  3. vue - 前置工作

    vue 中文官网:https://cn.vuejs.org/ vue ES6语法:https://www.cnblogs.com/zhouyangla/p/7225335.html vue Debug ...

  4. hdu 4707 Pet(DFS &amp;&amp; 邻接表)

    Pet Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  5. Effective C++ 条款二 用编译器替换预编译器

    /************************************************************************/ /* C++条款二:用编译器替换预编译器 */ / ...

  6. C#语言基础语句

    case,switch,break的使用 Console.WriteLine("1.汉堡"); Console.WriteLine("2.薯条"); Conso ...

  7. linux 命令之 watch

    watch能够帮你监測一个命令的执行结果,省得你一遍遍的手动执行.在Linux下.watch是周期性的执行下个程序.并全屏显示执行结果.你能够拿他来监測你想要的一切命令的结果变化,比方 tail 一个 ...

  8. xcode编译 debug版或release 版

    编译debug版本或release 版本 在Run和Stop按钮的右边有一个工程名 点击工程名,选择Manage Schemes 选择Edit... 左侧选择Run ProjectName.app 右 ...

  9. jdk8新特性Stream

    Stream的方法描述与实例 1,filter  过滤 Person p1 = new Person(); p1.setName("P1"); p1.setAge(10); Per ...

  10. SPOJ:Robot(数学期望)

    There is a robot on the 2D plane. Robot initially standing on the position (0, 0). Robot can make a ...