NITableViewActions Deprecations and New APIs

24 views
Skip to first unread message

Jeff Verkoeyen

unread,
Nov 2, 2012, 1:35:54 PM11/2/12
to nimb...@googlegroups.com
Hey gang!

I'm going to be pushing a change to NITableViewActions in a little bit that will deprecate the existing API and introduce a new one. This means a little bit of deprecation warning cleanup for anyone using NITableViewActions, but it's worth it. So here's what's going down.

What's being deprecated
- what it's being replaced with
Why?

initWithController:
- initWithTarget:
The new actions object allows you to attach both blocks and selectors to objects. In order to support implementing actions on arbitrary objects it's important that we switch to an id-based target rather than requiring a strict UIViewController.

attachTapAction:toObject:
attachDetailAction:toObject:
attachNavigationAction:toObject:
attachTapAction:toClass:
attachDetailAction:toClass:
attachNavigationAction:toClass:
- attachBlockToObject:tap:
- attachBlockToObject:detail:
- attachBlockToObject:navigation:
- attachBlockToClass:tap:
- attachBlockToClass:detail:
- attachBlockToClass:navigation:
Per Apple's recommendation, the block argument is now the last argument in the method invocation. This cleans the invocation code because we don't have dangling toObject: parameters after inline block declarations.

The above deprecations also introduce a subtle naming change that allows us to define a new API for attaching selectors to objects, specifically the use of "Block" rather than "Action". With the new update, an "action" may be either a block or a selector or both.

With that, presented below are the new APIs for attaching selectors to objects.

- attachSelectorToObject:tap:
- attachSelectorToObject:detail:
- attachSelectorToObject:navigation:
- attachSelectorToClass:tap:
- attachSelectorToClass:detail:
- attachSelectorToClass:navigation:

These methods work similarly to their block-based counterparts.

Now that we have two ways to attach actions to objects, when should you use one over the other? The answer is personal, but in general you should choose selectors over blocks for complex actions that would otherwise pollute the method with long and complex blocks.

All of the old methods are still available in the API and route to the new-style methods, so updating to master will simply give you a number of deprecation warnings. Cleaning these up should be a fairly straightforward updating of the method parameter order. I sadly don't have a simple find-and-replace regex to offer here, but I found that it took about 15 minutes to completely update the Nimbus sample projects.

Cheers!
- Jeff
Reply all
Reply to author
Forward
0 new messages