// // Singleton.m // iSales-NPD // // Created by Jack on 2016/10/12. // Copyright © 2016年 United Software Applications, Inc. All rights reserved. // #import "RASingleton.h" #import "NotificationNameCenter.h" @interface RASingleton () @property (nonatomic,strong) NSMutableDictionary *globalParameters; @end @implementation RASingleton #pragma mark - Global Parameter - (NSMutableDictionary *)globalParameters { if (!_globalParameters) { _globalParameters = [NSMutableDictionary dictionary]; } return _globalParameters; } - (void)setGlobalParameter:(id)param forKey:(NSString *)key { if (param == nil || key == nil) { return; } [self.globalParameters setObject:param forKey:key]; } - (id)globalParameterForKey:(NSString *)key { if (key == nil) { return nil; } return [self.globalParameters objectForKey:key]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } + (instancetype)sharedInstance { static RASingleton *singleton = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ singleton = [[RASingleton alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:singleton selector:@selector(handleLogin:) name:User_LoginOK_Notification object:nil]; }); return singleton; } - (void)setGlobal_lock:(BOOL)global_lock { _global_lock = global_lock; if (global_lock) { [[NSNotificationCenter defaultCenter] postNotificationName:Lock_Permission_Notification object:nil]; } else { [[NSNotificationCenter defaultCenter] postNotificationName:unLock_Permission_Notification object:nil]; } } - (void)resetGlobalLock { _global_lock = NO; } - (void)handleLogin:(NSNotification *)notification { self.currentOrderIsMerged = NO; } - (NSString *)homeClickedItemName { if (!_homeClickedItemName) { _homeClickedItemName = @""; } return _homeClickedItemName; } - (NSString *)deliveryString { if (!_deliveryString) { _deliveryString = @""; } return _deliveryString; } @end