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

Adds a nondestructive -attributeTypeName property to attributes #86

Merged
merged 4 commits into from
Jan 7, 2012
Merged

Adds a nondestructive -attributeTypeName property to attributes #86

merged 4 commits into from
Jan 7, 2012

Conversation

robrix
Copy link
Contributor

@robrix robrix commented Jan 7, 2012

It is usable as a replacement for both -scalarAttributeType and -objectAttributeType, and pulls from the attributeValueTypeName userInfo field if available.

-attributeTypeName uses the “attributeValueTypeName” field in userInfo if available, defaulting to the scalarAttributeType if any, or else the objectAttributeType suffixed with a *.

Intended for use in the templates, deprecating both -scalarAttributeType and -objectAttributeType.

Use case: transformable attributes with “id” as their type (as opposed to the unidiomatic and frankly weird NSObject *).
@robrix
Copy link
Contributor Author

robrix commented Jan 7, 2012

I should note, this would close #85.

This is done by adding -scalarAttributeTypeName, -scalarAccessorMethodName, and -scalarFactoryMethodName to NSAttributeDescription.

-scalarAttributeTypeName returns the same thing as -scalarAttributeType, except that where that uses short, int, and long long, the new method uses int16_t, int32_t, and int64_t.

To allow simple boxing and unboxing with NSNumber, -scalarAccessorMethodName and -scalarFactoryMethodName return the appropriate values for the scalar type, e.g. boolValue, longLongValue, and numberWithShort:.
@robrix
Copy link
Contributor Author

robrix commented Jan 7, 2012

I did not mean to add the second commit to this pull request! Oh well, it provides a fix for #2. Do with it what you will! I leave my code humbly at your mercy.

rentzsch added a commit that referenced this pull request Jan 7, 2012
[NEW] Better return value types: `int16_t`/`int32_t`/`int64_t` instead of `short`/`long`/`long long` and `id` instead of `NSObject*`. closes #2, #85 (Rob Rix)
@rentzsch rentzsch merged commit c82f11a into rentzsch:master Jan 7, 2012
@rentzsch
Copy link
Owner

rentzsch commented Jan 7, 2012

I found some other issues examining the test mule MOs, which I fixed up here: 25bc9fc

You may want to take a look, especially since I removed support for attributeValueTypeName attribute userInfo key since I couldn't figure how it differs from the existing attributeValueClassName support. Maybe I'm missing something?

@robrix
Copy link
Contributor Author

robrix commented Jan 7, 2012

Main difference with attributeValueTypeName was that it would allow you to specify e.g. id without having the * appended onto it. attributeValueClassName seems to handle that by replacing NSObject * with id.

On the other hand, other type names would also be possible with attributeValueTypeName that aren’t with this handling of attributeValueClassName, for example Class and id<SomeProtocol>.

The intention was basically “type name, verbatim.” I still kind of feel like this is valuable for the protocol case especially (without resorting to NSObject<SomeProtocol> *), which is something I’ve occasionally wanted. What do you think?

Sorry about the NSNumber mistakes. Derp :)

@rentzsch
Copy link
Owner

rentzsch commented Jan 8, 2012

Ah, I see.

I don't think we need direct "type name, verbatim" support if we keep the generation code smart enough. For instance, I added NSObject* detection, replacing it with an id. So I think we already have all the bases covered with that simple heuristic.

Let me know if you have any other examples that aren't correctly handled.

@robrix
Copy link
Contributor Author

robrix commented Jan 8, 2012

As I mentioned, Class and id.

Rob Rix, Unknown Quantity.

On 2012-01-07, at 10:51 PM, Jonathan 'Wolf' Rentzsch [email protected] wrote:

Ah, I see.

I don't think we need direct "type name, verbatim" support if we keep the generation code smart enough. For instance, I added NSObject* detection, replacing it with an id. So I think we already have all the bases covered with that simple heuristic.

Let me know if you have any other examples that aren't correctly handled.


Reply to this email directly or view it on GitHub:
#86 (comment)

@rentzsch
Copy link
Owner

rentzsch commented Jan 8, 2012

Oh, I misunderstood your text. Yup, those aren't covered. I'm more inclined to make attributeValueClassName mean "type name, verbatim" than add another userInfo key, and accept the fact folks will need to tweak their model to add the asterisk.

@robrix
Copy link
Contributor Author

robrix commented Jan 8, 2012

That works for me.

@robrix
Copy link
Contributor Author

robrix commented Jan 8, 2012

Although of course, folks will have to edit their data models too, which is rather more tedious.

@JoeOsborn
Copy link

Devil's advocate time, I guess: What's wrong with special-casing an understanding of Class and id and id<ProtocolName[,…]> when generating from an attributeValueClassName? It seems irritating to have to throw asterisks all over the place in userInfo fields in the data model.

@robrix
Copy link
Contributor Author

robrix commented Jan 9, 2012

Yes, that would be a good approach. We still have to change the templates, but not all the data models.

@rentzsch
Copy link
Owner

rentzsch commented Jan 9, 2012

@JoeOsborn: yup, I was already thinking along those lines myself. Good to hear you're on the same wavelength.

I'm thinking about something like this (in mostly-JavaScript):

if (attributeValueClassName.match(/Class/)) return attributeValueClassName; // Class
if (attributeValueClassName.match(/</)) return attributeValueClassName; // id<Protocol1,Protocol2>
if (attributeValueClassName.match(/NSObject */)) return "id"; // NSObject *
return attributeValueClassName;

ddrccw pushed a commit to ddrccw/mogenerator that referenced this pull request Jan 20, 2014
---

It is usable as a replacement for both -scalarAttributeType and -objectAttributeType, and pulls from the attributeValueTypeName userInfo field if available.
ddrccw pushed a commit to ddrccw/mogenerator that referenced this pull request Jan 20, 2014
---

It is usable as a replacement for both -scalarAttributeType and -objectAttributeType, and pulls from the attributeValueTypeName userInfo field if available.
ddrccw pushed a commit to ddrccw/mogenerator that referenced this pull request Jan 20, 2014
[NEW] Better return value types: `int16_t`/`int32_t`/`int64_t` instead of `short`/`long`/`long long` and `id` instead of `NSObject*`. closes rentzsch#2, rentzsch#85 (Rob Rix)
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