In practical development, we often need to build models based on dictionaries. It's disgusting to think about it every time you hit a bunch of code. You can write a classification for nsdictionary and create a property.
Nsdictionary+property.h
#import <Foundation/Foundation.h>@interface nsdictionary-(void ) Createpropertycode; @end
Nsdictionary+property.m
#import "Nsdictionary+property.h"@implementationNsdictionary (property)//Iskindofclass: Determines whether the current class or subclass//Generate Property Code = = According to all keys in the dictionary- (void) createpropertycode{nsmutablestring*codes = [nsmutablestringstring]; //Traverse Dictionary[Self enumeratekeysandobjectsusingblock:^ (ID_nonnull Key,ID_nonnull value, BOOL *_nonnull stop) {NSString*Code; if([Value iskindofclass:[nsstringclass]]) {Code= [NSString stringWithFormat:@"@property (nonatomic, strong) NSString *%@;", key]; } Else if([Value iskindofclass:nsclassfromstring (@"__nscfboolean")]) {Code= [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL%@;", key]; } Else if([Value Iskindofclass:[nsnumberclass]]) {Code= [NSString stringWithFormat:@"@property (nonatomic, assign) Nsinteger%@;", key]; } Else if([Value Iskindofclass:[nsarrayclass]]) {Code= [NSString stringWithFormat:@"@property (nonatomic, strong) Nsarray *%@;", key]; } Else if([Value Iskindofclass:[nsdictionaryclass]]) {Code= [NSString stringWithFormat:@"@property (nonatomic, strong) nsdictionary *%@;", key]; }[Codes AppendFormat:@"\n%@\n", code]; }]; NSLog (@"%@", codes); }@end
IOS Dictionary auto-generation model