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是一个抽象的基类,表示一个独立的计算单元,可以为子类提供有用且线程安全的建立状态,优先级,依赖和取消等操作. ...
随机推荐
- kibana dev tools快捷键
kibana dev tools快捷键 ctrl+enter 提交请求 ctrl+i 自动缩进 ctrl+enter 提交请求 down 打开自动补全菜单 enter或tab 选中项自动补全 esc ...
- ``Accordian'' Patience
``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patience, the rule ...
- VC中常见API函数使用方法(经验版)
***********************************************声明*************************************************** ...
- 通过Java反射做实体查询
我们在使用hibernate的时候,查询的时候都会和实体中的一些字段相结合去查询,当然字段少了,还算是比较简单,当字段多了,就不那么容易了,所以就自己写了个方法,根据实体中的字段信息去查询,废话不多说 ...
- 腾讯云图片鉴黄集成到C# SQL Server 怎么在分页获取数据的同时获取到总记录数 sqlserver 操作数据表语句模板 .NET MVC后台发送post请求 百度api查询多个地址的经纬度的问题 try{}里有一个 return 语句,那么紧跟在这个 try 后的 finally {}里的 code 会 不会被执行,什么时候被执行,在 return 前还是后? js获取某个日期
腾讯云图片鉴黄集成到C# 官方文档:https://cloud.tencent.com/document/product/641/12422 请求官方API及签名的生成代码如下: public c ...
- 【iOS开源码】(1):CCLHTTPServer
我从没有见过比 CCLHTTPServer 更简单的 iOS HTTP server了.你甚至不用创建不论什么子类就可以使用它.对于大部分任务,这个小巧但强悍的server能够满足你的须要. 它简单到 ...
- 远程连接mysql速度慢的解决方法:skip-name-resolve取消DNS的反向解析
PHP远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常,出现这种问题的主要原因是,默认安装的 MYSQL开启了DNS的反向解析,在MY.INI(WINDOW ...
- HDU 6125 Free from square 状态压缩DP + 分组背包
Free from square Problem Description There is a set including all positive integers that are not mor ...
- 【bzoj4653】[Noi2016]区间
离散化+线段树 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstri ...
- 教你如何配置Ubuntu用于高效、高质量的发送邮件
本文首发在: http://mengxi.me/how-to-setup-ubuntu-sendmail-to-deliver-email-fast-and-reliable/ 在网站上线后,经常会遇 ...