NSDictionary+TBXSafe.m 967 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // NSDictionary+TBXSafe.m
  3. // assemble
  4. //
  5. // Created by apple on 2020/11/2.
  6. // Copyright © 2020 kingsunsoft. All rights reserved.
  7. //
  8. #import "NSDictionary+TBXSafe.h"
  9. #import <objc/runtime.h>
  10. #import "NSObject+ImpChange.h"
  11. @implementation NSDictionary (TBXSafe)
  12. + (void)load{
  13. static dispatch_once_t onceToken;
  14. dispatch_once(&onceToken, ^{
  15. [self SwizzlingMethod:@"initWithObjects:forKeys:count:" systemClassString:@"__NSPlaceholderDictionary" toSafeMethodString:@"initWithObjects_st:forKeys:count:" targetClassString:@"NSDictionary"];
  16. });
  17. }
  18. -(instancetype)initWithObjects_st:(id *)objects forKeys:(id<NSCopying> *)keys count:(NSUInteger)count {
  19. NSUInteger rightCount = 0;
  20. for (NSUInteger i = 0; i < count; i++) {
  21. if (!(keys[i] && objects[i])) {
  22. break;
  23. }else{
  24. rightCount++;
  25. }
  26. }
  27. self = [self initWithObjects_st:objects forKeys:keys count:rightCount];
  28. return self;
  29. }
  30. @end