我的单身人士看起来如下:
标题
#import <Foundation/Foundation.h>
@interface MyManager : NSObject
{
MyManager *_sharedObject;
}
@property(nonatomic,copy) NSString * nameTitle;
@property(nonatomic,copy) NSString * nameDescription;
//assets
@property (nonatomic, strong) NSMutableArray * assets;
+ (id)sharedInstance;
@end
执行
#import "MyManager.h"
@implementation MyManager
@synthesize listingTitle;
@synthesize listingDescription;
//Assets
@synthesize assets;
+ (id)sharedInstance
{
static dispatch_once_t pred = 0;
__strong static id _sharedObject = nil;
dispatch_once(&pred, ^{
_sharedObject = [[self alloc] init]; // or some other init method
});
return _sharedObject;
}
@end
我想知道再添加 2 种方法,让我可以随时初始化和重置属性。我正在考虑使用 init 方法进行初始化,并添加另一种方法来重置。这会是正确的方法吗?
像这样的东西:
-(id)init {
self = [super init];
if (self != nil) {
[self reset];
}
return self;
}
-(void)reset {
self.listingTitle=@"";
self.listingDescription=@"";
}
这是正确的方法吗?谢谢