object_getClass
2015-10-30 13:08
363 查看
object_getClass得到一个实例的类
输出:
/** * Returns the class of an object. * * @param obj The object you want to inspect. * * @return The class object of which \e object is an instance, * or \c Nil if \e object is \c nil. */ OBJC_EXPORT Class object_getClass(id obj) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
#import <Foundation/Foundation.h> @interface Person : NSObject @property(nonatomic, assign) NSInteger age; @property(nonatomic, strong) NSString * name; @end
#import "Person.h" @interface Person () @property(nonatomic, strong) NSString * sex; @end @implementation Person - (instancetype)init { self = [super init]; if (self) { self.sex = @"-----------"; self.age = 19; self.name = @"sb"; } return self; } @end
#import "ViewController.h" #import <objc/runtime.h> #import "Person.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. Person * p1 = [[Person alloc] init]; Class c1 = object_getClass(p1); NSLog(@"%@", c1); Person * p2 = [[[c1 class] alloc] init]; NSLog(@"%@", p2.name); }
输出:
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- Java Runtime Environment 5.0 Update 12 下载
- php set_magic_quotes_runtime() 函数过时解决方法
- Asp.Net 程序错误Runtime Error原因与解决
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 检测iOS设备是否越狱的方法
- System 类 和 Runtime 类的常用用法介绍
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- 举例详解iOS开发过程中的沙盒机制与文件