OC 对象本质

118 阅读1分钟

//#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <objc/runtime.h>
struct Student_IMPL {
    Class isa;
    int _no;
    int _age;
    
};


@interface Student : NSObject
{
    @public
    int _no;
    int _age;
//    double num;
//    int count;
    char go;
    char go1;
    char go2;
    char go3;
    char go4;
    char go5;
    char go6;
    


}


@end
@implementation Student






@end
int main(int argc, char * argv[]) {


   


    NSString * appDelegateClassName;
    @autoreleasepool {
        appDelegateClassName = NSStringFromClass([AppDelegate class]);
        Student *stu = Student.new;
        stu->_no = 4;
        stu->_age = 43;
        struct Student_IMPL *stuIMP = (__bridge struct Student_IMPL*)stu;
        NSLog(@"%d  %d",stuIMP->_age,stuIMP->_no);
        NSLog(@"Student类大小 %ld",class_getInstanceSize([Student class]));
        NSLog(@"Student类大小 %ld",class_getInstanceSize([NSObject class]));


//        类对象
        Class objClass1 = [stu class];
        Class objClass2 = [Student class];
        Class objClass3 = object_getClass(stu);
    }
    return 0;
   
}

2020-05-28 16:36:13.547553+0800 SDK2.0.0[46267:6736820] 43  4
2020-05-28 16:36:13.548062+0800 SDK2.0.0[46267:6736820] Student类大小 24
2020-05-28 16:36:13.548184+0800 SDK2.0.0[46267:6736820] Student类大小 8
(lldb) p objClass1
(Class) $0 = Student
(lldb) p/x objClass1
(Class) $1 = 0x0000000101de1ae0 Student
(lldb) p/x objClass2
(Class) $2 = 0x0000000101de1ae0 Student
(lldb) p/x objClass3
(Class) $3 = 0x0000000101de1ae0 Student
(lldb) p stu
(Student *) $4 = 0x0000600003cb2860
(lldb) p/x stu
(Student *) $5 = 0x0000600003cb2860
(lldb)