Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b149ff

Browse files
author
Jim Puls
committed
More documentation; style cleanup
1 parent85c48fc commit7b149ff

File tree

19 files changed

+69
-277
lines changed

19 files changed

+69
-277
lines changed

‎CodeGenTestApp/CGTAAppDelegate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// Copyright (c) 2014 Square, Inc. All rights reserved.
77
//
88

9-
#import<UIKit/UIKit.h>
109

1110
@interfaceCGTAAppDelegate :UIResponder <UIApplicationDelegate>
1211

‎CodeGenTestApp/CGTADetailViewController.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright (c) 2014 Square, Inc. All rights reserved.
77
//
88

9-
#import<UIKit/UIKit.h>
10-
119

1210
@interfaceCGTADetailViewController :UIViewController
1311

‎CodeGenTestApp/CGTAMasterViewController.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright (c) 2014 Square, Inc. All rights reserved.
77
//
88

9-
#import<UIKit/UIKit.h>
10-
119

1210
@interfaceCGTAMasterViewController :UICollectionViewController
1311
@end

‎CodeGenTestApp/CGTAMasterViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import"CGTAImagesCatalog+RuntimeHackery.h"
1212
#import"CGTAMainStoryboardIdentifiers.h"
1313

14+
1415
@interfaceCGTAFlagCollectionViewCell :UICollectionViewCell
1516

1617
@property (nonatomic,weak)IBOutlet UIImageView *imageView;

‎CodeGenTestApp/main.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// Copyright (c) 2014 Square, Inc. All rights reserved.
77
//
88

9-
#import<UIKit/UIKit.h>
109

1110
#import"CGTAAppDelegate.h"
1211

‎Documentation/colorpicker.png

33.2 KB
Loading

‎Documentation/storyboardhaters.png

324 KB
Loading

‎README.md

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,75 @@
1-
#objc-assetgen
1+
#codegenutils
2+
3+
We love Xcode 5. It's been adding way cool features at a really fast pace, and adopting these features is the quickest way to bliss in life.
4+
5+
(Or at least iOS development bliss.)
6+
7+
But sometimes these boss new features don't quite get all the way. In the interest of meeting the tools halfway, we present three small code generators to improve your life in subtle ways.
8+
9+
##objc-assetgen
210

311
Xcode 5 has an awesome new feature called "[asset catalogs](https://developer.apple.com/technologies/tools/features.html)", allowing you to specify all of your image variants and resizable cap insets in a single place.
412

513
Unfortunately, to get the full benefits, you have to set your deployment target to iOS 7; otherwise, Xcode will dutifully put all of the images into your app bundle but totally ignore all of your resizable insets with only a build warning.
614

15+
And even if you're targeting iOS 7, you'll still have to deal with typing string filenames correctly. And[everybody knows that stringly-typed code is bad.](http://c2.com/cgi/wiki?StringlyTyped)
16+
717
But shucks! The important and awesome part is the editor, and it puts all of the data out in super-readable JSON. We should be able to do a poor man's version that reads in the data and spits out some code to give you most of the benefits.
818

9-
##Usage
19+
###Usage
1020

1121
Call`objc-assetgen` with the`.xcassets` paths as arguments from the directory into which it should output the code.
1222

13-
For an asset catalog named "Foo" containing image sets "Bar" and "Baz", you'll get`FooCatalog.h` and`FooCatalog.m`, with class methods`+ (UIImage *)imageForBar` and`+ (UIImage *)imageForBaz`. Put them in your DerivedSources folder and you're good to go.
23+
For an asset catalog named "Foo" containing image sets "Bar" and "Baz", you'll get`FooCatalog.h` and`FooCatalog.m`, with class methods`+ (UIImage *)barImage` and`+ (UIImage *)bazImage`. Put them in your DerivedSources folder and you're good to go.
24+
25+
##objc-colordump
26+
27+
On Mac OS X, the standard system color picker has a tab for palette-based colors:
28+
29+
![System color picker](Documentation/colorpicker.png)
30+
31+
One little-known feature of this color picker tab is that you can create your own palettes and fill them with the custom colors for your app.
32+
33+
In the spirit of[Once and Only Once](http://c2.com/cgi/wiki?OnceAndOnlyOnce), once you've used these colors in your storyboards and nib files, you won't want to have to define them again for that rare occasion you're using them in code. Luckily, your custom color palettes are just files in`~/Library/Colors`, and we can read them and give your app access to them.
34+
35+
Running the tool will also install the palette into your system color picker, so the other developers on your team can use your colors in their storyboards.
36+
37+
###Usage
1438

15-
##Command-line options
39+
Call`objc-colordump` with the`.clr` paths as arguments from the directory into which it should output the code.
40+
41+
For a color palette named "Foo" colors named "Bar" and "Baz", you'll get`FooColorList.h` and`FooColorList.m`, with class methods`+ (UIColor *)barColor` and`+ (UIColor *)bazColor`. Put them in your DerivedSources folder and you're good to go.
42+
43+
##objc-identifierconstants
44+
45+
[Storyboards](https://developer.apple.com/library/ios/documentation/general/conceptual/Devpedia-CocoaApp/Storyboard.html) are great. They let you visually lay out your interface and define the interactions between different screens in a way that's much more compact than writing a ton of view code.
46+
47+
At least I think so. But if you go and search for more information on storyboards, one of the first things you'll find is this Stack Overflow answer:
48+
49+
[![Storyboard haters](Documentation/storyboardhaters.png)](http://stackoverflow.com/a/19457257/6010)
50+
51+
We already fixed the part about code reuse with`objc-colordump`, and now we can fix the parts about failures at runtime. If we generate some code to turn your string identifiers into compiler-checked constants, we can avoid a whole class of problems.
52+
53+
###Usage
54+
55+
Call`objc-identifierconstants` with the`.storyboard` paths as arguments from the directory into which it should output the code.
56+
57+
For a storyboard named "Foo" with string identifiers "Bar" and "Baz" somewhere in it, you'll get`FooStoryboardIdenfitiers.h` and`FooStoryboardIdentifiers.m` with`extern NSString *const FooStoryboardBarIdentifier` and`extern NSString *const FooStoryboardBazIdentifier` in it. Put them in your DerivedSources folder and you're good to go.
58+
59+
##Command-line options (common to all three tools)
1660

1761
Usage:
18-
*`objc-assetgen [-o <path>] [-f <path>] [-p <prefix>] [<paths>]`
19-
*`objc-assetgen -h`
62+
*`objc-assetgen [-6] [-o <path>] [-f <path>] [-p <prefix>] [<paths>]`
63+
*`objc-colordump [-6] [-o <path>] [-f <path>] [-p <prefix>] [<paths>]`
64+
*`objc-identifierconstants [-6] [-o <path>] [-f <path>] [-p <prefix>] [<paths>]`
2065

2166
Options:
2267
<dl>
68+
<dt><code>-6</code></dt><dd>Target iOS 6 in addition to iOS 7</dd>
2369
<dt><code>-o&lt;path></code></dt><dd>Output files at <code>&lt;path></code></dd>
24-
<dt><code>-f&lt;path></code></dt><dd>Search for*.xcassets folders starting from <code>&lt;path></code></dd>
70+
<dt><code>-f&lt;path></code></dt><dd>Search forinput files starting from <code>&lt;path></code></dd>
2571
<dt><code>-p&lt;prefix></code></dt><dd>Use <code>&lt;prefix></code> as the class prefix in the generated code</dd>
2672
<dt><code>-h</code></dt><dd>Print this help and exit</dd>
27-
<dt><code>&lt;paths></code></dt><dd>Input files; this and/or-f are required.</dd>
73+
<dt><code>&lt;paths></code></dt><dd>Input files; this and/or`-f` are required.</dd>
2874
</dl>
75+

‎Shared/CGUCodeGenTool.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#import<libgen.h>
1212

13+
1314
@interfaceCGUCodeGenTool ()
1415

1516
@property (copy)NSString *toolName;
@@ -39,11 +40,11 @@ + (int)startWithArgc:(int)argc argv:(const char **)argv;
3940
printf("Usage:%s [-6] [-o <path>] [-f <path>] [-p <prefix>] [<paths>]\n",basename((char *)argv[0]));
4041
printf("%s -h\n\n",basename((char *)argv[0]));
4142
printf("Options:\n");
43+
printf(" -6 Target iOS 6 in addition to iOS 7\n");
4244
printf(" -o <path> Output files at <path>\n");
4345
printf(" -f <path> Search for *.%s folders starting from <path>\n", [[selfinputFileExtension]UTF8String]);
4446
printf(" -p <prefix> Use <prefix> as the class prefix in the generated code\n");
4547
printf(" -h Print this help and exit\n");
46-
printf(" -6 Target iOS 6 in addition to iOS 7\n");
4748
printf(" <paths> Input files; this and/or -f are required.\n");
4849
return0;
4950
}

‎assetgen/AGCatalogParser.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import"AGCatalogParser.h"
1010

11+
1112
@interfaceAGCatalogParser ()
1213

1314
@property (strong)NSArray *imageSetURLs;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp