fix to class check for nil

convenience functions
init functions
This commit is contained in:
Pfeil, Scott Robert 2019-01-25 16:12:28 -05:00
parent 88b18372c8
commit edf59e0e78
8 changed files with 16 additions and 11 deletions

View File

@ -36,8 +36,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
@implementation MVMCoreActionHandler
+ (nullable instancetype)sharedActionHandler {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].actionHandler.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].actionHandler;
return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].actionHandler classToVerify:self];
}
- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {

View File

@ -42,8 +42,7 @@
static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
+ (nullable instancetype)sharedCache {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].cache.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].cache;
return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].cache classToVerify:self];
}
- (nullable instancetype)init {

View File

@ -13,7 +13,7 @@
@implementation MVMCoreLoggingHandler
+ (nullable instancetype)sharedLoggingHandler {
if ([MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].loggingDelegate.class otherClass:self throwException:NO]) {
if ([MVMCoreObject sharedInstance].loggingDelegate && [MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].loggingDelegate.class otherClass:self throwException:NO]) {
return (MVMCoreLoggingHandler *)[MVMCoreObject sharedInstance].loggingDelegate;
} else {
return nil;

View File

@ -13,8 +13,7 @@
@implementation MVMCoreSessionObject
+ (nullable instancetype)sharedGlobal {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].session.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].session;
return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].session classToVerify:self];
}
- (nullable NSDictionary *)getInitialParameters {

View File

@ -47,8 +47,7 @@
@implementation MVMCoreSessionTimeHandler
+ (nullable instancetype)sharedSessionHandler {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].sessionHandler.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].sessionHandler;
return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].sessionHandler classToVerify:self];
}
- (instancetype)init {

View File

@ -26,4 +26,7 @@
// returns if the class is not the same or a subclass of the other class. Can pass throw an exception as well
+ (BOOL)classIsInstanceTypeOfClass:(Class)theClass otherClass:(Class)otherClass throwException:(BOOL)throwException;
// Calls the above function with throw exception yes if the object is not nil. Returns the object. Convenience function for one liner in initializer.
+ (id)initializerClassCheck:(nullable NSObject *)object classToVerify:(Class)classToVerify;
@end

View File

@ -147,4 +147,11 @@
return YES;
}
+ (id)initializerClassCheck:(nullable NSObject *)object classToVerify:(Class)classToVerify {
if (object) {
[self classIsInstanceTypeOfClass:object.class otherClass:classToVerify throwException:YES];
}
return object;
}
@end

View File

@ -27,8 +27,7 @@
@implementation MVMCoreViewControllerMappingObject
+ (nullable instancetype)sharedViewControllerMappingObject {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].viewControllerMapping.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].viewControllerMapping;
return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].viewControllerMapping classToVerify:self];
}
#pragma mark - View Controller Mapping