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是一个抽象的基类,表示一个独立的计算单元,可以为子类提供有用且线程安全的建立状态,优先级,依赖和取消等操作. ...
随机推荐
- 转: 性能测试应该怎么做? (from coolshell.cn)
转自: http://coolshell.cn/articles/17381.html 偶然间看到了阿里中间件Dubbo的性能测试报告,我觉得这份性能测试报告让人觉得做这性能测试的人根本不懂性能测试, ...
- APACHE局域网配置域名访问
/** * * @email 514320008@qq.com * @author jshaibozhong * */ 1,打开APACHE的目录 \Apache2\conf\extra\httpd ...
- C#实现模拟登录百度并发送私信
首先获取Token,根据Token获取PubliKey,使用RSA加密POST数据 private Regex _regex = new Regex(@"\{.*\}", Rege ...
- no matching provisioning profiles found
问题:真机连上,执行这个提示. 解决: 项目->targets->Bulid Settings-> 1,Provisioning Profile->选择配置Bundle Ide ...
- 各种加载效果,适合做加载loading动画效果 Eclipse版
Animation.rar 链接: http://pan.baidu.com/s/1c0QkOz2 密码: kd57
- 怎样更改Linux中默认的openjdk为自己安装的JDK
(1)/etc/profileexport JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera/export PATH=$PATH:$JAVA_HOME/binexpor ...
- java接口的一些想法
最近一直在闷头往前看<thingking in java> ,但是却由于赶了进度而忘记了初衷.当学到集合的时候,回头却发现,我连最基本的接口都不明白.查了一上午资料,现在明白例如一点点,写 ...
- (转)C中的volatile用法
volatile 影响编译器编译的结果,指出,volatile 变量是随时可能发生变化的,与volatile变量有关的运算,不要进行编译优化,以免出错,(VC++ 在产生release版可执行码时会进 ...
- Swift中字符串转化为Class的方法
Swift中字符串转化为Class的方法 在开发中有时候会根据字符串进行对应类的转化,这样我们就可以动态根据服务器返回的字段,动态的加载类,比如优酷,微博等APP会在节假日等动态的TabBar.这样可 ...
- Android实现RecyclerView的下拉刷新和上拉载入很多其它
需求 先上效果图, Material Design风格的下拉刷新和上拉载入很多其它. 源代码地址(欢迎star) https://github.com/studychen/SeeNewsV2 假设对于 ...