#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. hadoop2.7.1 nutch2.3 二次开发windows环境

     Hadoop windows编译: 能够略过这一段,直接下载hadoo2.7.1 bin文件.我的资源里有终于生成的winutils.exe和一些native code,放在bin文件夹即可了 參 ...

  2. android_checkbox_dialog 设计 是不是要开起 默认不提示对话框

    android_checkbox_dialog设计是不是开起默认不提示 package com.example.android_checkbox_dialog; import android.app. ...

  3. Android Auto Scroll ViewPager (Smooth)

    项目信息 项目地址 https://github.com/benniaobuguai/android-auto-scroll-viewpager 特性 支持自动平滑切换海报.相册等,无限次循环轮播 手 ...

  4. 【转载】细聊分布式ID生成方法

    一.需求缘起 几乎所有的业务系统,都有生成一个记录标识的需求,例如: (1)消息标识:message-id (2)订单标识:order-id (3)帖子标识:tiezi-id 这个记录标识往往就是数据 ...

  5. 使用ViewPager多页面滑动切换以及动画效果

    https://github.com/eltld/Viewpager

  6. BIOS维修技术

    BIOS是电脑中最基础且最重要的程序,为电脑提供最低级且最直接的硬件控制,电脑的原始操作都是依照固化在BIOS里的程序来完成的.因此如果BIOS出现故障将会导致影响电脑的正常工作.BIOS故障有很多, ...

  7. PandoraBox 支持3G无线上网卡(联通卡3G卡)(一)

    一:笔者采用的是系统是OpenWrt之PandoraBox,内核版本3.3.8:硬件设备是MTK的7620开发板. 其中怎么搭建openwrt开发环境在此不用多说,因为既然想实现3G无线上网卡拨号上网 ...

  8. HDU 3249 Test for job (有向无环图上的最长路,DP)

     解题思路: 求有向无环图上的最长路.简单的动态规划 #include <iostream> #include <cstring> #include <cstdlib ...

  9. reviews of learn python3 the hard way

    Almost every time,I try my best to write a long review of the book I have read. But this time I want ...

  10. Maven group, artifact or version defined in the pom file do not match the file ...

    在把library上传到bintray空间的时候报以下错误 Could not upload to 'https://api.bintray.com/content/ping/maven/comm-a ...