123456789101112131415161718192021222324252627282930 |
- //
- // NSDictionary+Safe.m
- // MSYOUPAI
- //
- // Created by YoMi on 2023/11/7.
- //
- #import "NSDictionary+Safe.h"
- #import "NSObject+ImpChangeTool.h"
- #import <objc/runtime.h>
- @implementation NSDictionary (Safe)
- + (void)load{
- [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
|