Workaround to create a model when a member variable name conflict occurs

Source: Internet
Author: User

When you build a model, the parsed file contains keywords in the UI, such as Id,description,self

There are 2 workarounds.

1. Change a name as the name of the member variable, assign a value to the member variable, but this method is not very convenient, when the variable name too much writing will be inconvenient.

2. Of course there are ways to write less code,

Call SetDescription when assigning a value to _mydescription:

@property (nonatomic,copy,setter=setdescription:) NSString * mydescription;

-(void) SetValue: (ID) value Forundefinedkey: (NSString *) key

{

If there is a key named description in the dictionary, but a property named description cannot be defined in the class, you can define the value Mydescription store description

if ([Key isequaltostring:@ "description"]) {

Self. Mydescription=value;

}

NSLog (@ "%@", key);

}

This is used when [model Setvaluesforkeyswithdictionary:dic];

The DIC key corresponds to the member variable name in the model, and the value is the value to be assigned; This method assigns the name of the member variable in the dictionary model to the model with the same value as the DIC key name.

Workaround to create a model when a member variable name conflict occurs

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.