IOS Dictionary auto-generation model

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.