Skip to content

Provide camel case => underscore conversions for object => dictionary#42

Open
markshiz wants to merge 4 commits into
aryaxt:masterfrom
markshiz:master
Open

Provide camel case => underscore conversions for object => dictionary#42
markshiz wants to merge 4 commits into
aryaxt:masterfrom
markshiz:master

Conversation

@markshiz

Copy link
Copy Markdown

Right now dictionary from object creation performs a non-optional underscore => camel case conversion, in order to make the library consistent with itself, provide the inverse mapping.

Right now dictionary from object creation performs a non-optional underscore => camel case conversion, in order to make the library consistent with itself, provide the inverse mapping.
@aryaxt

aryaxt commented Jan 21, 2016

Copy link
Copy Markdown
Owner

Thanks for the PR
Generating underscore keys should be an optional feature, not a replacement for existing naming conventions. Specially since underscore feature was added to the library later as an enhancement.

Methods

- (id)dictionaryFromObject:(NSObject *)object;
- (id)dictionaryFromObject:(NSObject *)object useUnderscoreKeys:(BOOL)useUnderscoreKeys;
  • Second one will replace the first one and based on the boolean flag it would either create regular keys or underscore keys
  • First one simply calls into the first one with the flag set to false

@markshiz

Copy link
Copy Markdown
Author

@aryaxt Good thought. I couldn't find that the opposite conversion was optional. It struck me that that should be as well. Do you agree?

@MeGaPk

MeGaPk commented Mar 4, 2016

Copy link
Copy Markdown

+1.
Need convert Object to Dictionary with CamelCase

@aryaxt

aryaxt commented Mar 4, 2016

Copy link
Copy Markdown
Owner

@markshiz Sorry completely forgot to respond to this, but camel case was initially used for OCMapper, and later I added support to check for underscore and handle them if needed

@MeGaPk camel case is the convention used in swift and objective c for property names, so as long as you have followed that it should just create keys in camel case same as property names

@MeGaPk

MeGaPk commented Mar 14, 2016

Copy link
Copy Markdown

@aryaxt i mean, convert Object (NSString *helloWorld="asd";) to dict ({"hello_world":"asd"}), for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants