Created
June 7, 2010 22:02
-
-
Save jtbandes/429252 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// replace annoying boilerplate with declarative justice using FunctionalKit: | |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
if (cell == nil) { | |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; | |
} | |
// => | |
// nota bene: category on UITableView for convenient factory method is highly recommended. | |
id maybeCell = [[aTableView maybe] dequeueReusableCellWithIdentifier:CellIdentifier]; | |
UITableViewCell *cell = [maybeCell orJustFromBlock:^{ return [UITableViewCell cellWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; }]; |
Zomg, good point. Damn Objective-C not being a lazy-evaluating language!
I need to make a HOM for forcing operations to be lazy.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's a good example. However, I added the block even with no configuration for a good reason: if you use your original code, you'll be creating extra cells whether or not they're needed.