Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Allow category method name prefix to be specified. #32

Closed
wants to merge 11 commits into from

Conversation

ebaker355
Copy link

This PR allows the category method name prefix to be set to something other than ac. When the prefix matches what other categories are using in a project, it makes it clear that the category belongs to that project, and was not imported via an external framework. Also, in the case where several asset catalogs exist in a project, it can be useful to use a different prefix for each one. If no prefix is specified, the default ac is used.

commit 8f6d5c8
Merge: 360bc82 6b378e8
Author: Baker, Eric (MONHC-C) <eric.baker@hyatt.com>
Date:   Fri Jan 29 15:27:54 2016 -0600

    Merge branch 'feature/specify-prefix' into develop

commit 6b378e8
Author: Baker, Eric (MONHC-C) <eric.baker@hyatt.com>
Date:   Fri Jan 29 15:26:26 2016 -0600

    Add method name prefix option.

commit 0ed5396
Author: Baker, Eric (MONHC-C) <eric.baker@hyatt.com>
Date:   Fri Jan 29 11:51:20 2016 -0600

    Rename FrameworkPrefix to MethodNamePrefix
# Conflicts:
#	Cat2Cat/main.m
@designatednerd
Copy link
Contributor

Hey @ebaker355: I like this idea! Do you mind updating the sample projects so we can verify the tests on those pass with this new change? Got a couple other questions I'll ask inline.

```
--asset-catalog="Resources/Images.xcassets"
```
```
--asset-catalog="Resources/Media.xcassets"
```
- The prefix for the category method names. If not specified, the default is `ac`. Must be at least 2 characters, and conform to valid method naming rules:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing you mention is possible in your PR comment but isn't quite clear in this documentation: What happens if multiple asset catalogs are specified?

Do you need to add multiple prefixes for the method name? Is the first method name prefix passed in used for every catalog? How do you specify which prefix is for which catalog?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are good questions that I hadn't thought of.

I suppose the prefixes should be added to an array, just like the asset names are, and applied in the same order as on the command line. I'm thinking that in the case where more catalogs are specified than prefixes, the last prefix specified will be used for the remaining catalogs, for the case where all catalogs should share the same prefix; on the other hand, more prefixes than catalogs will result in the leftover prefixes being ignored. Do you agree? Or have another ideas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To complicate things a bit, glob patterns (i.e., shell wildcard type patterns) can be passed as asset catalog names, so a single asset catalog parameter can turn into multiple asset catalogs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's a tricky one. However, if someone is using glob patterns in a run script build phase, I'd think they're not overly worried about assigning specific prefixes, since the processing order is essentially undefined. If they wanted to ensure a specific prefix matches a certain asset catalog, they should probably be specific about both in the command line, imho.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if maybe we're making this too complicated—maybe Cat2Cat should get invoked separately for each prefix? That is, if you've got some stuff with prefix abc and some with prefix xyz, you should run Cat2Cat 2 separate times? That'd avoid all the issues about aligning different asset catalogs with different prefixes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... in fact, when I opened the sample projects to start writing tests for this PR, I noticed that the categories files would simply be overwritten, unless there was a way to specify a different name for the category as well.

Maybe I've opened a can of worms here... 😿

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having the category names be prefixed isn't really a bad idea and would fix that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but... how do we apply the prefixes for each usage? For example, in our project (which I think is following pretty standard convention), we prefix our category methods with xyz_, but our category names are prefixed with XYZ. So, our categories would look like:

UIImage+XYZAssetCatalog.h/m and
+ (UIImage *)xyz_SomeImage;

Would we accept only one prefix and mutate it to match these usages, forcing this convention? Or do we allow separate prefixes for methods and categories names to be specified?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I were using it, I'd want one prefix, forced lowercase and separated with _ for methods and forced uppercase for the category... so I'm thinking either:

  • just the one parameter and enforce that usage; or
  • have one parameter that'd enforce that usage and two optional parameters to override just the method prefix and just the other prefix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will update this PR with what we've discussed so far, and we can go from there. Thanks again you guys for all the time you've spent thinking this thru! :)

@ebaker355
Copy link
Author

@designatednerd My iOS team lead is very interested in using Cat2Cat for our project. However, there are a few updates he would like us to make. One was in this PR, the ability to specify the category prefix.

Unrelated to this PR, another change we'd like to explore is the ability to generate factory classes instead of categories on UIImage. However, I'm not sure that's a great fit for Cat2Cat. It seems to me that perhaps that should be a different project. Any thoughts? Thanks!

@vokal-isaac
Copy link
Contributor

@designatednerd Given what @ebaker355 is looking to do, I'm thinking maybe we'd want to work this like that other tool we're using internally, where the template applied is arbitrary, the platform/language flags select the template(s) to use, and there's a --template parameter that'll take an arbitrary template? If we did that, generating factory classes or pretty much anything else would be a matter of creating the templates and passing them in to Cat2Cat.

@designatednerd
Copy link
Contributor

@vokal-isaac Ooh, yah, I like that idea too. Let's discuss tomorrow.

@ebaker355: Give us a day to mull it over and we'll give you a heads up.

@ebaker355
Copy link
Author

@designatednerd & @vokal-isaac No problem guys! Thanks for taking the time to consider these ideas. We're not in a huge rush, and we want to ensure any changes are beneficial for everyone.

description:@"Prefix for method names (defaults to ac)"
blockWithArgument:^(NSString *value) {
methodNamePrefix = [value copy];
}];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this needs to be done with a block?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to be able to perform a check for nil on the variable. BRLOptionParser didn't seem to be happy if I passed in a pointer to nil. A nil check was needed to bypass the validation check, if the parameter wasn't specified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that to avoid specifying the default value on the variable declaration?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, since its an optional arg.

I suppose the default "ac" could just be used as the default value, but that constant was defined lower in the code base, and I didn't know if I should move it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, given that you're stating the default value in the description, it might as well move up here. I'm inclined to think the simplification of not having to use the block is also worth the move.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll make the update.

@ebaker355
Copy link
Author

As of now, I am swamped with work. I will reopen this PR when I have time to complete the changes. Hopefully soon!

@ebaker355 ebaker355 closed this Feb 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants