---
title: "Save Time and Code With JMWhenTapped"
url: https://deallocatedobjects.com/posts/jmwhentapped
author: Jake Marsh
published: 2011-04-27
updated: 2013-11-16
topics: ["iOS Development", "Open Source", "Things I Made"]
description: "I’ve just released a new little helper library for iOS development. It’s called JMWhenTapped. It’s is a simple little syntactical-sugar addition to all UIView objects, as well as any class that inherits from UIView."
---

# Save Time and Code With JMWhenTapped

By Jake Marsh, April 27, 2011. HTML: https://deallocatedobjects.com/posts/jmwhentapped

I've just released a new little helper library for iOS development. It's called `JMWhenTapped`. It's is a simple little syntactical-sugar addition to all `UIView` objects, as well as any class that inherits from `UIView`. It allows you to assign touch-up, touch-down, and tapped (touched down then up) actions to a `UIView` object using a convenient blocks-style syntax.

### Installation

Clone [the repo](http://github.com/jakemarsh/JMWhenTapped). Add the `JMWhenTapped` folder to your iOS 4 project. `#import "JMWhenTapped.h"` wherever you'd like to use the syntax.

### Examples & Usage

Use it like this:

``` objc	
[myView whenTapped:^{
	NSLog(@"I was tapped!");
}];
```
	
Or like this:

``` objc
[myView whenTouchedDown:^{
	NSLog(@"I was touched down!");
}];
```
	
And also like this:

``` objc
[myView whenTouchedUp:^{
	NSLog(@"I was touched up!");		
}];
```

### The Different Actions

The `whenTapped:` method should be used in cases where you simply want something to happen when the user taps on a view (i.e. you are concerned with performing some action when their finger is down then up, like changing to a "pressed" state.)

The `whenTouchedDown:` method should be used when you want to trigger some action when the user touches down on your view.

The `whenTouchedUp:` method should be used when you want to trigger some action when the user touches up on your view.

### Demo

Included in [the repo](http://github.com/jakemarsh/JMWhenTapped) is a demo Xcode project that illustrates a quick example of how to use `JMWhenTapped`.
