日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oc40--类的启动过程

發布時間:2025/5/22 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oc40--类的启动过程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// // main.m // 類的啟動過程#import <Foundation/Foundation.h> #import "Person.h" #import "GoodStudent.h"/* 只要程序啟動就會將所有類的代碼加載到內存中, 放到代碼區load方法會在當前類被加載到內存的時候調用, 有且僅會調用一次如果存在繼承關系, 會先調用父類的load方法, 再調用子類的load方法*/int main(int argc, const char * argv[]) {/*2017-08-23 15:05:08.882568+0800 類的啟動過程[36713:860727] Car類被加載到內存了2017-08-23 15:05:16.019104+0800 類的啟動過程[36713:860727] Person類被加載到內存了2017-08-23 15:05:17.390692+0800 類的啟動過程[36713:860727] Student類被加載到內存了2017-08-23 15:05:19.161607+0800 類的啟動過程[36713:860727] GoodStudent類被加載到內存了還沒有使用類的時候就加載到內存了。*/Person *p1 = [[Person alloc] init];Person *p2 = [[Person alloc] init];Person *p3 = [[Person alloc] init];Person *p4 = [[Person alloc] init];GoodStudent *gstu = [[GoodStudent alloc] init];/*2017-08-23 15:08:55.461633+0800 類的啟動過程[36844:863122] Person initialize2017-08-23 15:09:01.543395+0800 類的啟動過程[36844:863122] Studnet initialize2017-08-23 15:09:06.376914+0800 類的啟動過程[36844:863122] GoodStudent initialize */return 0; } // // Person.h#import <Foundation/Foundation.h>@interface Person : NSObject @end // // Person.m#import "Person.h"@implementation Person // 只要程序啟動就會將所有類的代碼加載到內存中, 放到代碼區 // load方法會在當前類被加載到內存的時候調用, 有且僅會調用一次 // 如果存在繼承關系, 會先調用父類的load方法, 再調用子類的load方法 + (void)load {NSLog(@"Person類被加載到內存了"); }// 當當前類第一次被使用的時候就會調用(創建類對象的時候) // initialize方法在整個程序的運行過程中只會被調用一次, 無論你使用多少次這個類都只會調用一次 // initialize用于對某一個類進行一次性的初始化 // initialize和load一樣, 如果存在繼承關系, 會先調用父類的initialize再調用子類的initialize + (void)initialize {NSLog(@"Person initialize"); }@end // // Student.h#import "Person.h"@interface Student : Person@end // // Student.m#import "Student.h"@implementation Student + (void)load {NSLog(@"Student類被加載到內存了"); } + (void)initialize {NSLog(@"Studnet initialize"); } @end // // GoodStudent.h#import "Student.h"@interface GoodStudent : Student@end // // GoodStudent.m#import "GoodStudent.h"@implementation GoodStudent + (void)load {NSLog(@"GoodStudent類被加載到內存了"); } + (void)initialize {NSLog(@"GoodStudent initialize"); }@end // // Car.h#import <Foundation/Foundation.h>@interface Car : NSObject@end // // Car.m#import "Car.h"@implementation Car + (void)load {NSLog(@"Car類被加載到內存了"); } + (void)initialize {NSLog(@"Car initialize"); } @end

?

轉載于:https://www.cnblogs.com/yaowen/p/7418320.html

總結

以上是生活随笔為你收集整理的oc40--类的启动过程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。