<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>iPhone Application Development</title>
	<atom:link href="http://iphoneappsforlife.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://iphoneappsforlife.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sun, 02 Aug 2009 19:21:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='iphoneappsforlife.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>iPhone Application Development</title>
		<link>http://iphoneappsforlife.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://iphoneappsforlife.wordpress.com/osd.xml" title="iPhone Application Development" />
	<atom:link rel='hub' href='http://iphoneappsforlife.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Two finger gestures (pinch/etc) on iPhone Simulator</title>
		<link>http://iphoneappsforlife.wordpress.com/2009/08/02/two-finger-gestures-pinchetc-on-iphone-simulator/</link>
		<comments>http://iphoneappsforlife.wordpress.com/2009/08/02/two-finger-gestures-pinchetc-on-iphone-simulator/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 19:21:10 +0000</pubDate>
		<dc:creator>groundhog</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://iphoneappsforlife.wordpress.com/?p=10</guid>
		<description><![CDATA[How to simulate multiple finger gestures with the iPhone simulator.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iphoneappsforlife.wordpress.com&amp;blog=8830082&amp;post=10&amp;subd=iphoneappsforlife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I accidentally stumbled today on how to simulate multi touch gestures.  It appears you can only simulate two touches at once.</p>
<p>To do begin simulating a multitouch gesture,  you simply hold down the Option key and you will see two gray circles appear, much like this:</p>
<div id="attachment_11" class="wp-caption alignnone" style="width: 389px"><a href="http://iphoneappsforlife.files.wordpress.com/2009/08/twofingertouch.png"><img class="size-full wp-image-11" title="twofingertouch" src="http://iphoneappsforlife.files.wordpress.com/2009/08/twofingertouch.png?w=379&#038;h=717" alt="Two Fingers on iPhone" width="379" height="717" /></a><p class="wp-caption-text">Two Fingers on iPhone</p></div>
<p>If you move the mouse around the display the two dots will move in mirror image fashion.  The gesture is centered around the center of the screen.  Clicking while holding the option key will cause the two fingers to touch the screen.</p>
<p>It does, however, appear impossible to center the gesture any where other than the screen center.</p>
<p>Additional (well, not really) information may be found in the <a onclick="return mugicPopWin(this,event);" oncontextmenu="mugicRightClick(this);" href="http://developer.apple.com/IPhone/library/documentation/Xcode/Conceptual/iphone_development/125-Using_iPhone_Simulator/iphone_simulator_application.html#//apple_ref/doc/uid/TP40007959-CH9-SW3" target="_blank">iPhone Simulator Guide&#8217;s section on Performing Gestures</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iphoneappsforlife.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iphoneappsforlife.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iphoneappsforlife.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iphoneappsforlife.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iphoneappsforlife.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iphoneappsforlife.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iphoneappsforlife.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iphoneappsforlife.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iphoneappsforlife.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iphoneappsforlife.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iphoneappsforlife.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iphoneappsforlife.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iphoneappsforlife.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iphoneappsforlife.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iphoneappsforlife.wordpress.com&amp;blog=8830082&amp;post=10&amp;subd=iphoneappsforlife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iphoneappsforlife.wordpress.com/2009/08/02/two-finger-gestures-pinchetc-on-iphone-simulator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e8ad2f135acaf791c4f0083d73c85ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">groundhog</media:title>
		</media:content>

		<media:content url="http://iphoneappsforlife.files.wordpress.com/2009/08/twofingertouch.png" medium="image">
			<media:title type="html">twofingertouch</media:title>
		</media:content>
	</item>
		<item>
		<title>Regular Expression Engine for Objective-C</title>
		<link>http://iphoneappsforlife.wordpress.com/2009/08/01/regular-expression-engine-for-objective-c/</link>
		<comments>http://iphoneappsforlife.wordpress.com/2009/08/01/regular-expression-engine-for-objective-c/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 20:01:56 +0000</pubDate>
		<dc:creator>groundhog</dc:creator>
				<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://iphoneappsforlife.wordpress.com/?p=3</guid>
		<description><![CDATA[A very simple match oriented regular expression engine in objective-c.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iphoneappsforlife.wordpress.com&amp;blog=8830082&amp;post=3&amp;subd=iphoneappsforlife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Regular expressions are one of the more useful constructs in computing, and there is no Cocoa support for regular expressions in NSString or related objects.  So I wrote myself one.</p>
<p>RegexEngine.h</p>
<pre class="brush: cpp;">
#import &lt;regex.h&gt;
@interface RegexResult : NSObject
{
	NSString *originalRegex;
	NSString *matchedString;
	NSArray *matches;
	NSArray *ranges;
}

@property (nonatomic, retain) NSString *originalRegex;
@property (nonatomic, retain) NSString *matchedString;
@property (nonatomic, retain) NSArray *matches;
@property (nonatomic, retain) NSArray *ranges;
+(RegexResult *)allocWithResults:(NSString *)regex matchedString:(NSString *)matched positionalMatches:(NSArray *)pmatches positionalRanges:(NSArray *)pranges;

@end

@interface RegexEngine : NSObject {

}

+(RegexResult*)match:(NSString *) regex against:(NSString *)candidate options:(int)options error:(NSError**)error;

@end
</pre>
<p>RegexEngine.m</p>
<pre class="brush: cpp;">
//
//  RegexEngine.m
//  Manna Duel
//
//  Created by Robert Mark Waugh on 5/31/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import &lt;regex.h&gt;
#import &quot;RegexEngine.h&quot;

@implementation RegexResult

@synthesize originalRegex;
@synthesize matchedString;
@synthesize matches;
@synthesize ranges;

+(RegexResult *)allocWithResults:(NSString *)regex matchedString:(NSString *)matched positionalMatches:(NSArray *)pmatches positionalRanges:(NSArray *)pranges
{
	RegexResult *result = [[RegexResult alloc] init];
	result.originalRegex = [regex copy];
	result.matchedString = [matched copy];
	result.matches = [pmatches copy];
	result.ranges = [pranges copy];

	return result;
}

-(void) dealloc
{
	[super dealloc];

	[originalRegex release];
	[matchedString release];
	[matches release];
	[ranges release];
}

@end

@implementation RegexEngine

+(RegexResult *)match:(NSString *) regex against:(NSString *)candidate options:(int)options error:(NSError**)error
{
	regex_t compiledRegEx;
	int compileResult = regcomp( &amp;compiledRegEx, [regex UTF8String], options | REG_EXTENDED );
	if( compileResult )
	{
		//handle error
		char errorBuffer[ 1024 ];
		regerror(compileResult, &amp;compiledRegEx, errorBuffer, 1024 );
		NSString *errorMessage = [NSString stringWithUTF8String:errorBuffer];
		return nil;
	}

	regmatch_t matches[ compiledRegEx.re_nsub + 1 ]; // storage includes the entire string at 0

	int matchResult = regexec( &amp;compiledRegEx, [candidate UTF8String], compiledRegEx.re_nsub + 1, matches, 0 );

	if( matchResult == 1 )
		return [RegexResult allocWithResults:regex matchedString:@&quot;&quot; positionalMatches:[NSArray arrayWithObjects:nil] positionalRanges:[NSArray arrayWithObjects:nil]];

	if( matchResult )
	{
		char errorBuffer[ 1024 ];
		regerror(matchResult, &amp;compiledRegEx, errorBuffer, 1024 );
		NSString *errorMessage = [NSString stringWithUTF8String:errorBuffer];
		return nil;
	}

	NSMutableArray *matchedStrings = [[NSMutableArray alloc] init];
	NSMutableArray *matchRanges = [[NSMutableArray alloc] init];

	for( int i = 0; i &lt;= compiledRegEx.re_nsub; i++ )
	{
		if( matches[ i ].rm_so == -1 )
		{
			[matchedStrings addObject:@&quot;&quot;];
			[matchRanges addObject:[NSValue valueWithRange:NSMakeRange(0, 0)]];
		}

		size_t matchLength = matches[ i ].rm_eo - matches[ i ].rm_so;
		char matchBuffer[ matchLength + 1 ];
		strncpy(matchBuffer, [candidate UTF8String] + matches[ i ].rm_so, matchLength);
		matchBuffer[matchLength ] = '';
		[matchedStrings addObject:[NSString stringWithUTF8String:matchBuffer]];
		[matchRanges addObject:[NSValue valueWithRange:NSMakeRange(matches[ i ].rm_so, matchLength)]];
	}

	return [RegexResult allocWithResults:regex matchedString:candidate positionalMatches:matchedStrings positionalRanges:matchRanges];
}

@end
</pre>
<p>Here is an example from an application I wrote which does template substitution according to the following syntax:<br />
[First Person Male!First Person Female/Second Person]<br />
If the person using the app is reading their version of the template, they get the First Person male or female depending on their configured gender.<br />
If the template is coming from another person, the reader in the app sees the second person version of the template.</p>
<pre class="brush: cpp;">
	RegexResult *results = [[RegexEngine match:@&quot;\\(([^\\!]+)\\!([^\\)]+)\\)&quot; against:text options:REG_EXTENDED error:&amp;error] autorelease];
	while( results &amp;&amp; [results.matches count] )
	{
		NSString *choice;
		int personIndex = self.firstPerson + 1;
		NSRange substringRange = [(NSValue *)[results.ranges objectAtIndex:0] rangeValue];
		NSString *substring = (NSString *)[results.matches objectAtIndex:personIndex];
		RegexResult *subResults = [[RegexEngine match:@&quot;([^/]+)/(.*)&quot; against:substring options:REG_EXTENDED error:&amp;error] autorelease];
		if( subResults &amp;&amp; [subResults.matches count] )
		{
			int genderIndex = self.gender + 1;
			choice = [subResults.matches objectAtIndex:genderIndex];
		}
		else
			choice = substring;

		returnValue = [returnValue stringByReplacingCharactersInRange:substringRange withString:choice];
		results = [[RegexEngine match:@&quot;\\(([^\\!]+)\\!([^\\)]+)\\)&quot; against:returnValue options:REG_EXTENDED error:&amp;error] autorelease];
	}
</pre>
<p>I plan to improve on this over time as necessary.<br />
Improvements desired:</p>
<ul>
<li>Make the regex engine itself be more object oriented.  Compile regular expressions into regex objects which have match and substitution methods on them.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iphoneappsforlife.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iphoneappsforlife.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iphoneappsforlife.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iphoneappsforlife.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iphoneappsforlife.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iphoneappsforlife.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iphoneappsforlife.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iphoneappsforlife.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iphoneappsforlife.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iphoneappsforlife.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iphoneappsforlife.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iphoneappsforlife.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iphoneappsforlife.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iphoneappsforlife.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iphoneappsforlife.wordpress.com&amp;blog=8830082&amp;post=3&amp;subd=iphoneappsforlife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iphoneappsforlife.wordpress.com/2009/08/01/regular-expression-engine-for-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e8ad2f135acaf791c4f0083d73c85ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">groundhog</media:title>
		</media:content>
	</item>
	</channel>
</rss>
