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是一个抽象的基类,表示一个独立的计算单元,可以为子类提供有用且线程安全的建立状态,优先级,依赖和取消等操作. ...
随机推荐
- Thinking in React(翻译)
下面是React官方文档中的Thinking inReact文章的翻译,第一次翻译英文的文章,肯定有非常多不对的地方,还望多多包涵. 原文地址:https://facebook.github.io/r ...
- android的armeabi和armeabi-v7a
在ANE中如果SDK调用了so库,则需要把so库放到ANE下Android-ARM/lib/armeabi (调试模式)或者 armeabi-v7a(发行模式)下. 可以贴个ADT代码说明问题: // ...
- Hadoop教程(一)
英文原文:cloudera,编译:ImportNew – Royce Wong Hadoop从这里开始!和我一起学习下使用Hadoop的基本知识,下文将以Hadoop Tutorial为主体带大家走一 ...
- HTML5面试题-b
感谢分享 面试有几点需要注意: 面试题目: 根据你的等级和职位变化,入门级到专家级:范围↑.深度↑.方向↑. 题目类型: 技术视野.项目细节.理论知识型题,算法题,开放性题,案例题. 进行追问: 可以 ...
- sphinx的配置和管理
网上配置文档众多,但是对着他们的文档来做老是出问题,于是花了点时间研究了一下,写成总结,方便以后查阅.也希望学习sphinx的朋友能少走弯路.Coreseek的安装请参考:http://blog.ch ...
- java基础知识汇总6(html篇)
五.html // 定义文档类型. < html> 定义 HTML 文档. < body> 定义文档的主体. < h1> to < h6> 定义 HTM ...
- oracle 11G direct path read 非常美也非常伤人
direct path read 在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这种全表扫描就是物理读了. 在10g中,都是通过gc buffer来读 ...
- Linux性能查看与分析--命令行工具介绍
本文介绍工作中常用的几个linux性能查看命令:top,sar,vmstat,iostat,pidstat等. 1.top top是最常用的linux性能分析工具,它能够实时的显示系统中各个进程的资源 ...
- 云打印-Beta-凡事预则立
凡事预则立 课程名称:软件工程1916|W(福州大学) 团队名称: 云打印 作业要求: 项目Beta冲刺(团队) 作业目标:Beta冲刺 团队队员 队员学号 队员姓名 个人博客地址 备注 221600 ...
- MVC 基于FormsAuthentication 方式的权限验证
1.登录的代码 1 [HttpPost] 2 public ActionResult Index(User entity) 3 { 4 User user = GetUser(entity.Name, ...