[英]iOS - shortcut to synthesize properties using extension
假設我有一個像這樣的類定義頭文件:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) SomeObject *managedObject;
@end
我的一個朋友告訴我,我可以使用類擴展名執行以下標頭定義,以更清晰地進行綜合,而不是在managedObject上定義@synthesize來創建獲取器/設置器:
#import "TSPAppDelegate.h"
@interface TSPAppDelegate () //notice the class extension here
@property (strong, nonatomic) SomeObject *managedObject; //this will already be synthesized since its an extension
@end
有人可以解釋一下這些擴展如何工作嗎?
我認為您的朋友不正確。 您必須@synthesize才能為您實現吸氣器/設置器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.