1. 程式人生 > 其它 >OC Extension Single(單例)

OC Extension Single(單例)

技術標籤:UI的封裝iosobjective-cswiftxcode

**

一直覺得自己寫的不是技術,而是情懷,一個個的教程是自己這一路走來的痕跡。靠專業技能的成功是最具可複製性的,希望我的這條路能讓你們少走彎路,希望我能幫你們抹去知識的蒙塵,希望我能幫你們理清知識的脈絡,希望未來技術之巔上有你們也有我。

**

在這裡插入圖片描述
使用

.h檔案
@interface LoginUserInfo : NSObject  寫在裡面
//做單例的目的是為了 全域性獲取登入模型中的資料
Single_interface(LoginUserInfo)

.m檔案
@implementation LoginUserInfo   寫在裡面
Single_implementation
(LoginUserInfo) A控制器 #import "ViewController.h" #import "FHXViewController.h" #import "BaseModel.h" @interface ViewController () @property (nonatomic,strong) BaseModel *model; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.
backgroundColor = [UIColor whiteColor]; self.model = [BaseModel new]; self.model.name = @"馮漢栩"; self.model.age = @"16"; [self.navigationController pushViewController:[FHXViewController new] animated:YES]; } @end B控制器 #import "FHXViewController.h" #import
"BaseModel.h"
@interface FHXViewController () @property (nonatomic,strong) BaseModel *model; @end @implementation FHXViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; self.model = [BaseModel new]; NSLog(@"name - %@",self.model.name); NSLog(@"age - %@",self.model.age); } @end

列印結果:
在這裡插入圖片描述