FunSize is an Objective-C framework comprised entirely of categories and intended to make Cocoa code shorter, while maintaining expressiveness. Here are a few approaches taken:
- Use blocks, a lot. They're pretty cool.
NSValueas invisible as possible. They are ugly and provide no additional information. Instead, provide messages for low-level data types (
- Replace absurdly long messages.
+functionWithName:takes one of five constants, each of which is prefixed with
[CAMediaTimingFunction easeOut]is much more succinct.
- Use reasonable defaults. Why is there no simple
NSImage? There is now. Additionally, 99% of
NSNotificationCenterusage is on the
-defaultCenter. So, FunSize has class-level versions of all
NSUserDefaults) instance messages.
FunSize was written while writing a Mac OS X application. Most of it presumably
works on iOS, but some
#ifdefs are probably needed for classes that don't
NSView). I used garbage collection in that application, and while
I attempted to insert
autorelease where applicable,
I haven't tested it extensively without GC (for this reason, I will not be
using GC in my next application).
New Note: It seems to work fine with reference counting now, as I've been running Leaks on my current project, which uses manual reference counting and makes extensive use of FunSize. If there are any remaining leaks, they would show up pretty clearly in Leaks anyways (which I assume everyone runs...right?)
The Xcode project target is a framework. Honestly, I haven't really used it, I simply added the source files to my project. Either way should work, however. I don't think Apple will be shipping FunSize any time soon, so you'll have to distribute it with each application anyways.
FunSize.h imports all of the other headers. Personally, I added it to my
prefix header so that FunSize feels like part of Cocoa. Actually, while I was
writing this, I was surprised to learn that
-[NSImage CGImage] isn't part
If you would like to contribute to FunSize, please follow this style.
- FunSize adds category methods.
- FunSize does not do anything else.
Note that this rule only applies to "public" things. "Helper" classes are
perfectly acceptable (see
NSTimer+FunSize.m), but they cannot be included in
any header files that are included with a compiled copy of FunSize. The same
applies to structs, typedefs, and anything else that isn't a category method.
Everything should be documented in appledoc style. There's no need to go overkill documenting parameters or returns that are really obvious to anyone smart enough to be the type of software developer that seeks out Objective-C category frameworks. But at least say something, since the appledoc pages look really ugly otherwise. Also, although appledoc warns about it, the classes that categories are being added to don't need to be documented.
Separate sections in header files like this:
#pragma mark - #pragma mark Recursive Subview Operations /** @name Recursive Subview Operations */
The final line is for appledoc, and should be left off in the implementation file.
Reasonably current documentation is available here.
Boring and easy things first: filenames are
Class+FunSize.m. Category declarations are
For naming actual messages, try to stay within Apple style (within reason). An
example is the usage of
CA* classes refer to it as a
"transform", so I added
-CATransform3DValue. Therefore, when I added key/value messages
NSObject to support
CATransform3D, I used the style
In general, just look at the current style and copy it. But basically, use
four spaces for indentation, since Xcode is bad at handling tabs. Use Allman
style for everything except blocks, which use K&R (why? I think it's most
readable like that).Declare pointers like this:
NSImage*. Put spaces in math
2 + 2, not
2+2), because it's good if math is actually readable.
FunSize is licensed under the ISC license.
Copyright (c) 2011, Nate Stedman <email@example.com> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.