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 class methods and strongly typed return values. #8

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

swiftal64
Copy link

See the updated example project for how category methods and strong types work.

Here's a quick example:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:CGTAMainStoryboardName bundle:nil];
CGTADetailViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:CGTAMainStoryboardDetailViewControllerIdentifier];

becomes

CGTADetailViewController *detailViewController = [CGTAMainStoryboard instantiateDetailViewController];

Segues, collection view cells, and table view cells are scoped to the view controller.

@puls
Copy link
Owner

puls commented Apr 2, 2014

This is amazing. But let's not introduce a mode. Please just change the behavior.

@swiftal64
Copy link
Author

I removed the mode and added some class generator methods (instead of printing strings). Let me know what you think.

@@ -7,6 +7,11 @@
// See the LICENSE file distributed with this work for the terms under
// which Square, Inc. licenses this file to you.

@interface CGTAFlagCollectionViewCell : UICollectionViewCell
Copy link
Owner

Choose a reason for hiding this comment

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

Any reason why you moved this?

Copy link
Author

Choose a reason for hiding this comment

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

In order for CGTAMasterViewController's dequeueImageCellForIndexPath:ofCollectionView: method to return an instance of CGTAFlagCollectionViewCell rather than UICollectionViewCell, it must be able to import the header file which defines that class. By moving the definition to the .h file, it will return this stronger type.

OY added 2 commits April 3, 2014 14:13
…ion view asked for a cell. Now it only computes allImages one time.

The identifiers now also output constraint original constant values, which is comes in handy when using auto layout.
Updated the sample app to show where this may be useful.
As a side effect, the sample app can now be used to quiz yourself on the country flags: tap a flag, think of the country name, then tap to see if you were correct.
@swiftal64
Copy link
Author

I implemented your recommendations, and added a new storyboard feature which caches the constraint constant values. If you think this should be a separate feature, let me know and I'll put it into another branch.

… files. In order to determine if a class can be imported, it now looks for a file of the same name as the class (e.g. MyCustomClass.h). While this isn’t perfect, it does seem to handle most of the cases at a significant performance boost. In order to show how dequeueImageCellForIndexPath:ofCollectionView: can return a CGTAFlagCollectionViewCell instance, the demo app has been updated to separate CGTAFlagCollectionViewCell into its own file.
if (sender.state == UIGestureRecognizerStateEnded) {
// the label was positioned perfectly via the storyboard, so now we can restore
// the perfect positioning easily, by refering to the constant that was generated for us!
self.countryNameTopConstraint.constant = self.countryNameTopConstraint.constant == 0 ? [self countryNameTopConstraintOriginalConstant] : 0;
Copy link
Owner

Choose a reason for hiding this comment

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

Holy equality comparisons between floating-point numbers and integer literals, Batman!

(Seriously, while this does work in this case, it's probably a bad idea to do this kind of thing in example code that will be copied ad nauseam.)

@puls puls changed the title Added Uber Mode which adds class methods and strongly typed return values. Adds class methods and strongly typed return values. Apr 11, 2014
@swiftal64
Copy link
Author

In regards to the first comment about floating point comparisons, what kind of fix are you looking for?

  1. The more correct comparison with a float (i.e. just changing 0 to 0.0f)?
  2. Using an epsilon in the comparison?
  3. Using a boolean to keep track of the visibility, eliminating all floating point comparisons entirely?

@puls
Copy link
Owner

puls commented Apr 12, 2014

Probably the third one.

…meHackeryMethod’ name. Added a boolean property to prevent the need for float comparison.
@puls
Copy link
Owner

puls commented May 8, 2014

This all looks good. You should update the docs before this is merged.

@swiftal64
Copy link
Author

I improved the support for UICollectionViews, and it now handles duplicate identifiers much better. The read me was also updated as you suggested.

OY and others added 4 commits May 13, 2014 14:26
… names. This gives the user more control over the generated method names. Added constants for scene identifiers. Added a way to generate documentation for generated methods.
…dded view controllers and segues with illegal identifiers to show that it handles them correctly (i.e. it no longer causes build errors). Created a test color scene which shows that Michael Thole’s color fix is correct.
…y of making a class extension was in place.
@jshier
Copy link

jshier commented Feb 10, 2015

@puls @oy65 This looks like exactly what my project needs. But is this project still going to be maintained? Any recommendations for similar tools?

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.

4 participants