QuickConfiguration.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #import "QuickConfiguration.h"
  2. #import <objc/runtime.h>
  3. #if __has_include("Quick-Swift.h")
  4. #import "Quick-Swift.h"
  5. #else
  6. #import <Quick/Quick-Swift.h>
  7. #endif
  8. @implementation QuickConfiguration
  9. #pragma mark - Object Lifecycle
  10. /**
  11. QuickConfiguration is not meant to be instantiated; it merely provides a hook
  12. for users to configure how Quick behaves. Raise an exception if an instance of
  13. QuickConfiguration is created.
  14. */
  15. - (instancetype)init {
  16. NSString *className = NSStringFromClass([self class]);
  17. NSString *selectorName = NSStringFromSelector(@selector(configure:));
  18. [NSException raise:NSInternalInconsistencyException
  19. format:@"%@ is not meant to be instantiated; "
  20. @"subclass %@ and override %@ to configure Quick.",
  21. className, className, selectorName];
  22. return nil;
  23. }
  24. #pragma mark - NSObject Overrides
  25. /**
  26. Hook into when QuickConfiguration is initialized in the runtime in order to
  27. call +[QuickConfiguration configure:] on each of its subclasses.
  28. */
  29. + (void)initialize {
  30. // Only enumerate over the subclasses of QuickConfiguration, not any of its subclasses.
  31. if ([self class] == [QuickConfiguration class]) {
  32. World *world = [World sharedWorld];
  33. [self configureSubclassesIfNeededWithWorld:world];
  34. }
  35. }
  36. #pragma mark - Public Interface
  37. + (void)configure:(Configuration *)configuration { }
  38. @end