Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for id Properties #54

Open
Adlai-Holler opened this issue May 28, 2017 · 9 comments
Open

Support for id Properties #54

Adlai-Holler opened this issue May 28, 2017 · 9 comments

Comments

@Adlai-Holler
Copy link
Contributor

I'd like to use plank for generating models for use inside an app i.e. no JSON parsing, and it'd be great to be able to specify @property id myThing and @property UIColor *myColor.

Is anyone else interesting in this capability?

@rahul-malik
Copy link
Collaborator

I think there is value in having other concrete types like UIColor but I'd want to avoid having id as a type since we lose pretty much any safety or usage guarantees for that property.

@Adlai-Holler
Copy link
Contributor Author

For example, I would like to use plank to generate objects for use in Texture, and sometimes these objects have a userInfo field that stores a plain id so that the user can attach arbitrary context info to something like a an image request. That would be one great use case for this.

@rahul-malik
Copy link
Collaborator

@Adlai-Holler - currently we offer things like serialization, copying support for all properties, how do you propose handling this in the case of id?

@rahul-malik
Copy link
Collaborator

rahul-malik commented Feb 10, 2018

Also what would the value of type be for this in the JSON schema?

@ay8s
Copy link
Contributor

ay8s commented Feb 15, 2018

@Adlai-Holler @rahul-malik I think we'd likely make use of this in our composer rewrite

@Adlai-Holler
Copy link
Contributor Author

For serialization, I think we could start with not serializing it. I don't know what the extensibility rules for JSON schema are, but maybe we could offer a hatch like, throwing this out there, "type": "$objc(id)"

The bigger question is whether plank is/should be suitable for generating non-serialized plain-old-NS-objects for use inside the app, or if it should be specialized for talking with a server.

Texture, for example, could make great use of a solid ObjC code generator.

@rahul-malik
Copy link
Collaborator

rahul-malik commented Feb 22, 2018

The main question for me is does it make sense to create types with properties of unknown types. I think id ends up reducing type-safety and could introduce more issues than it solves.

The only thing that is JSON / Server specific currently is the assumption that dictionaries always use NSString as the key type.

That said, I think there is probably value in having a way to have users declare type extensions outside of the ones listed in JSONSchema and it would be up to them to declare what the corresponding type is for each supported language they wish to generate.

@brurend
Copy link

brurend commented Mar 12, 2018

What about treat those cases similar to how Plank deals with NSDate?

The JSON value could be "any" string and with format you would define what kind of class it should be.

This way the responsibility would be up to each developer and not to Plank itself.

@rahul-malik
Copy link
Collaborator

@Adlai-Holler - working on a proposal to allow custom type extensions making plank a whole lot more flexible. I’ll forward when I have something to review

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

No branches or pull requests

4 participants