Object - c --- 클래스 의 본질

main.m
//
// main.m
// 06-    
//
// Created by apple on 13-8-8.
// Copyright (c) 2013  itcast. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Person.h"
#import "Student.h"
#import "GoodStudent.h"
/* 1.      ,              ,               +load  。      。 2.          ,        +initialize   3.     ,     (      +load  ,      +load  )       ,      (      +initialize  ,      +initialize  ) */

int main()
{
    // [[GoodStudent alloc] init];

    return 0;
}

void test1()
{
    Person *p = [[Person alloc] init];

    //[Person test];

    //        
    //     ==  
    Class c = [p class];
    [c test];

    Person *p2 = [[c new] init];


    NSLog(@"00000");
}

void test()
{
    //   Person      2 Person     
    Person *p = [[Person alloc] init];

    Person *p2 = [[Person alloc] init];

    Person *p3 = [[Person alloc] init];

    //          
    Class c = [p class];

    Class c2 = [p2 class];

    //          
    Class c3 = [Person class];


    NSLog(@"c=%p, c2=%p, c3=%p", c, c2, c3);

    //          ,  Class     ,     

    /*   Class    Person       Person       Person      */
}


Person.m
/*   :MJ   :   :    :Person.m */

#import "Person.h"

@implementation Person
+ (void)test
{
    NSLog(@"   test  ");
}


//         ,             。          +load  
+ (void)load
{
    NSLog(@"Person---load");
}

//             ,      +initialize  
+ (void)initialize
{
    NSLog(@"Person-initialize");
}

@end

Student.m
/*   :MJ   :   :    :Student.m */

#import "Student.h"

@implementation Student

//           
+ (void)load
{
    NSLog(@"Student---load");
}


+ (void)initialize
{
    NSLog(@"Student-initialize");
}


@end

GoodStudent.m
/*   :MJ   :   :    :Student.m */

#import "Student.h"

@implementation Student

//           
+ (void)load
{
    NSLog(@"Student---load");
}


+ (void)initialize
{
    NSLog(@"Student-initialize");
}


@end

Person+MJ.m
//
// Person+MJ.m
// 06-    
//
// Created by apple on 13-8-8.
// Copyright (c) 2013  itcast. All rights reserved.
//

#import "Person+MJ.h"

@implementation Person (MJ)
+ (void)load
{
    NSLog(@"Person(MJ)---load");
}
+ (void)initialize
{
    NSLog(@"Person(MJ)-initialize");
}
@end

좋은 웹페이지 즐겨찾기