1234567891011121314151617181920212223242526272829303132333435 |
- //
- // NSDictionary+TBXSafe.m
- // assemble
- //
- // Created by apple on 2020/11/2.
- // Copyright © 2020 kingsunsoft. All rights reserved.
- //
- #import "NSDictionary+TBXSafe.h"
- #import <objc/runtime.h>
- #import "NSObject+ImpChange.h"
- @implementation NSDictionary (TBXSafe)
- + (void)load{
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- [self SwizzlingMethod:@"initWithObjects:forKeys:count:" systemClassString:@"__NSPlaceholderDictionary" toSafeMethodString:@"initWithObjects_st:forKeys:count:" targetClassString:@"NSDictionary"];
- });
- }
- -(instancetype)initWithObjects_st:(id *)objects forKeys:(id<NSCopying> *)keys count:(NSUInteger)count {
- NSUInteger rightCount = 0;
- for (NSUInteger i = 0; i < count; i++) {
- if (!(keys[i] && objects[i])) {
- break;
- }else{
- rightCount++;
- }
- }
- self = [self initWithObjects_st:objects forKeys:keys count:rightCount];
- return self;
- }
- @end
|