<?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/"
	>

<channel>
	<title>Colin Eberhardt&#039;s Technology Adventures</title>
	<atom:link href="http://www.scottlogic.co.uk/blog/colin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk/blog/colin</link>
	<description>Colin Eberhardt&#039;s Technology Adventures</description>
	<lastBuildDate>Fri, 17 May 2013 09:47:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>HTML5 &#8211; It Just Got Real &#8211; Slides</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2013/05/html5-it-just-got-real-slides-and-photos/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2013/05/html5-it-just-got-real-slides-and-photos/#comments</comments>
		<pubDate>Thu, 16 May 2013 14:54:15 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=2417</guid>
		<description><![CDATA[TweetA couple of days ago we hosted a one-day conference, HTML5 &#8211; It Just Got Real, at the Royal Society buildings in London. I&#8217;m happy to say that the event was a great success, and that the Q&#038;A session that followed our talks was very lively! As promised, we have made all of our presentations [...]]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton2417" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F05%2Fhtml5-it-just-got-real-slides-and-photos%2F&amp;text=HTML5%20%26%238211%3B%20It%20Just%20Got%20Real%20%26%238211%3B%20Slides&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F05%2Fhtml5-it-just-got-real-slides-and-photos%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.scottlogic.co.uk/blog/colin/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>A couple of days ago we hosted a one-day conference, <a href="http://html5-it-just-got-real.com/">HTML5 &#8211; It Just Got Real</a>, at the Royal Society buildings in London. I&#8217;m happy to say that the event was a great success, and that the Q&#038;A session that followed our talks was very lively!</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/03/html5-just-got-real.png" alt="html5-just-got-real" width="495" height="269" class="aligncenter size-full wp-image-2376" /></p>
<p>As promised, we have made all of our presentations available online. The first three presentations have all been created using HTML5, whilst the last uses PowerPoint.</p>
<h2>Attention!</h2>
<p>These presentation were designed to work with the Chrome browser, and are navigated using the left and right arrow keys. They are not intended to be a demonstration of cross-browser HTML5, on the contrary! They illustrate the fact that HTML5 has not solved the need to consider specific browsers and browser-versions when writing code.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/05/keys.png" alt="keys" width="600" height="213" class="aligncenter size-full wp-image-2436" /></p>
<h2>HTML5 Revolution</h2>
<p> &#8211; by <a href="http://www.scottlogic.co.uk/blog/colin/">Colin Eberhardt</a>, you can <a href="http://colineberhardt.github.io/html5-revolution/">view the presentation in your browser</a>, and view the <a href="https://github.com/ColinEberhardt/html5-revolution">sourcecode on github</a>.</p>
<p><a href="http://colineberhardt.github.io/html5-revolution/"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/05/html5-revolution.png" alt="html5-it-just-got-real" width="600" height="384" class="aligncenter size-full wp-image-2419" /></a></p>
<p><br/><br/><br/></p>
<h2>HTML5 &#8211; It Just Got Real</h2>
<p> &#8211; by <a href="http://www.scottlogic.co.uk/blog/chris/">Chris Price</a>, you can <a href="http://chrisprice.github.io/html5-it-just-got-real/">view the presentation in your browser</a>, and view the <a href="https://github.com/chrisprice/html5-it-just-got-real">sourcecode on github</a>.</p>
<p><a href="http://chrisprice.github.io/html5-it-just-got-real/"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/05/html5-it-just-got-real.png" alt="html5-it-just-got-real" width="600" height="384" class="aligncenter size-full wp-image-2419" /></a></p>
<p><br/><br/><br/></p>
<h2>Designing the Future</h2>
<p> &#8211; by <a href="http://www.scottlogic.co.uk/blog/graham/">Graham Odds</a>, you can <a href="http://godds.github.io/designing-the-future/">view the presentation in your browser</a>, and view the <a href="https://github.com/godds/designing-the-future">sourcecode on github</a>.</p>
<p><a href="http://godds.github.io/designing-the-future/"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/05/designing-the-future.png" alt="designing-the-future" width="600" height="384" class="aligncenter size-full wp-image-2421" /></a></p>
<p><br/><br/><br/></p>
<h2>Cross-Platform Mobile Development</h2>
<p> &#8211; by <a href="http://www.scottlogic.co.uk/blog/colin/">Colin Eberhardt</a>, this presentation is <a href="http://www.slideshare.net/colineberhardt/cross-platform-mobile-development-you-tube-videos">hosted on slideshare</a>, with videos made available via YouTube.</p>
<p><a href="http://www.slideshare.net/colineberhardt/cross-platform-mobile-development-you-tube-videos"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/05/cross-platform.jpg" alt="cross-platform" width="600" height="384" class="aligncenter size-full wp-image-2427" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2013/05/html5-it-just-got-real-slides-and-photos/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Enhanced Windows Phone 8 Map Gestures</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2013/04/enhanced-windows-phone-8-map-gestures/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2013/04/enhanced-windows-phone-8-map-gestures/#comments</comments>
		<pubDate>Mon, 15 Apr 2013 09:34:19 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[codeproject]]></category>
		<category><![CDATA[gestures]]></category>
		<category><![CDATA[wp8]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=2405</guid>
		<description><![CDATA[TweetThis blog post describes the addition of a two-finger rotation and three-finger pitch gesture to the Windows Phone 8 Map control. You can see these gesture in action below: The WP8 release replaced the image-tile based Bing maps with a fully vector-rendered map from Nokia. Being vector-based, this map can be panned, zoomed, rotated and [...]]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton2405" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F04%2Fenhanced-windows-phone-8-map-gestures%2F&amp;text=Enhanced%20Windows%20Phone%208%20Map%20Gestures&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F04%2Fenhanced-windows-phone-8-map-gestures%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.scottlogic.co.uk/blog/colin/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p><em>This blog post describes the addition of a two-finger rotation and three-finger pitch gesture to the Windows Phone 8 Map control.</em></p>
<p>You can see these gesture in action below:</p>
<p><iframe width="640" height="480" src="http://www.youtube.com/embed/XunJ9sTXfH0" frameborder="0" allowfullscreen></iframe></p>
<p>The WP8 release replaced the image-tile based Bing maps with a fully vector-rendered map from Nokia. Being vector-based, this map can be panned, zoomed, rotated and rendered at an angle (i.e. pitched). However, much of this new functionality is not offered to the end user!</p>
<p>The WP8 supports the same gestures that the Bing WP7 map did, i.e. a single-fingered pan gesture and two-fingered pinch to zoom. What about rotation and pitch? Why not allow the user to modify these via gestures?</p>
<p>The key here is to add some new gestures that complement the existing one. I opted for the following:</p>
<ul>
<li><strong>Two-finger rotate</strong> – When the user places two fingers on the map this is currently used to zoom the display via a ‘spreading’ motion. However, if the user instead rotates the two touch points around the centre, the map should be rotated.</li>
<li><strong>Three-finger pitch</strong> – When the user places three fingers on the map, if they drag up or down, the map should adjust its pitch accordingly.</li>
</ul>
<p>These gestures are enabled simply by creating them with a reference to the map:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> MapRotationGesture<span style="color: #008000;">&#40;</span>map<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">new</span> MapPitchGesture<span style="color: #008000;">&#40;</span>map<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>If you don’t care how this all works, just <a href="https://github.com/ColinEberhardt/WP8-MapGestures">head over to github</a> and grab the code. If you want to find out more, read on …</p>
<h2>Suppressing The Existing Gestures</h2>
<p>In order to add these new gestures to the map, there needs to be a mechanism in place to suppress the existing gestures so that they do not interfere.</p>
<p>The technique I used is similar to a technique I demonstrated previously for <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control/" title="Suppressing Zoom and Scroll interactions in the Windows Phone 7 WebBrowser Control">suppressing pinch and scroll in the Windows Phone Browser control</a>. Both the Map and <code>WebBrowser </code>controls have a visual tree containing a number of user interface elements. The inner structure of the <code>Map</code> is shown below:</p>
<pre>
Microsoft.Phone.Maps.Controls.Map
  System.Windows.Controls.Border
    System.Windows.Controls.Border
      Microsoft.Phone.Maps.Controls.MapPresentationContainer
        MS.Internal.ExternalInputContainer
          System.Windows.Controls.Grid
            MS.Internal.TileHostV2
            Microsoft.Phone.Maps.Controls.RootMapLayer
</pre>
<p>The technique for suppressing interactions is quite simple, just add a <code>ManipulationDelta</code> event handler to each one of these elements, setting the event to handled. The complete code is show below:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// A base class for map gestures, which allows them to suppress the built-in map gestures.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MapGestureBase
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
  <span style="color: #008080; font-style: italic;">/// Gets or sets whether to suppress the existing gestures/</span>
  <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SuppressMapGestures <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">get</span><span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">set</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">protected</span> Map Map <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">get</span><span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">set</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> MapGestureBase<span style="color: #008000;">&#40;</span>Map map<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    Map <span style="color: #008000;">=</span> map<span style="color: #008000;">;</span>
    map<span style="color: #008000;">.</span><span style="color: #0000FF;">Loaded</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>s,e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> CrawlTree<span style="color: #008000;">&#40;</span>Map<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> CrawlTree<span style="color: #008000;">&#40;</span>FrameworkElement el<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    el<span style="color: #008000;">.</span><span style="color: #0000FF;">ManipulationDelta</span> <span style="color: #008000;">+=</span> MapElement_ManipulationDelta<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> c <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> c <span style="color: #008000;">&lt;</span> VisualTreeHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildrenCount</span><span style="color: #008000;">&#40;</span>el<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> c<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      CrawlTree<span style="color: #008000;">&#40;</span>VisualTreeHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChild</span><span style="color: #008000;">&#40;</span>el, c<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> FrameworkElement<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> MapElement_ManipulationDelta<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, ManipulationDeltaEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>SuppressMapGestures<span style="color: #008000;">&#41;</span>
      e<span style="color: #008000;">.</span><span style="color: #0000FF;">Handled</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>If you create an instance of this class and associate it with a map you can turn gestures on and off via the <code>SuppressMapGestures </code>property:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">var</span> gestureBase <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MapGestureBase<span style="color: #008000;">&#40;</span>map<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
gestureBase<span style="color: #008000;">.</span><span style="color: #0000FF;">SuppressMapGestures</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>NOTE: Unfortunately this doesn’t solve the ‘map in a pivot’ or ‘map in a panorama’ problem that many Windows Phone developers have struggled with – the gestures that are handled are not propagated to a parent control.</p>
<h2>A Rotation Gesture</h2>
<p>The user can rotate the map by placing two fingers on the screen then rotating them around their central point. Because two fingers are also used for the pinch-to-zoom gesture, a suitable threshold needs to be introduced. I have found that disabling rotation until the user has rotated by 10 degrees feels about right.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/04/RotationGesture.jpg" alt="RotationGesture" width="282" height="480" class="aligncenter size-full wp-image-2406" /></p>
<p>The code that implements the rotation is really quite simple, the <code>MapGestureBase </code> subclass is shown in its entirety below:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Adds a two-finger rotation gesture to a Map control.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MapRotationGesture <span style="color: #008000;">:</span> MapGestureBase
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
  <span style="color: #008080; font-style: italic;">/// Gets or sets the minimuum rotation that the user must apply in order to initiate this gesture.</span>
  <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">double</span> MinimumRotation <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">get</span><span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">set</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">?</span> _previousAngle<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> _isRotating<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> MapRotationGesture<span style="color: #008000;">&#40;</span>Map map<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">&#40;</span>map<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    MinimumRotation <span style="color: #008000;">=</span> <span style="color: #FF0000;">10.0</span><span style="color: #008000;">;</span>
    Touch<span style="color: #008000;">.</span><span style="color: #0000FF;">FrameReported</span> <span style="color: #008000;">+=</span> Touch_FrameReported<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Touch_FrameReported<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, TouchFrameEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">var</span> touchPoints <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTouchPoints</span><span style="color: #008000;">&#40;</span>Map<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touchPoints<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008080; font-style: italic;">// for the initial touch, record the angle between the fingers</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>_previousAngle<span style="color: #008000;">.</span><span style="color: #0000FF;">HasValue</span><span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        _previousAngle <span style="color: #008000;">=</span> AngleBetweenPoints<span style="color: #008000;">&#40;</span>touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span>, touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
&nbsp;
      <span style="color: #008080; font-style: italic;">// should we rotate?</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>_isRotating<span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #6666cc; font-weight: bold;">double</span> angle <span style="color: #008000;">=</span> AngleBetweenPoints<span style="color: #008000;">&#40;</span>touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span>, touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #6666cc; font-weight: bold;">double</span> delta <span style="color: #008000;">=</span> angle <span style="color: #008000;">-</span> _previousAngle<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Value</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span>delta<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&gt;</span> MinimumRotation<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
          _isRotating <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
          SuppressMapGestures <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
      <span style="color: #008000;">&#125;</span>
&nbsp;
      <span style="color: #008080; font-style: italic;">// rotate me</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_isRotating<span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        <span style="color: #6666cc; font-weight: bold;">double</span> angle <span style="color: #008000;">=</span> AngleBetweenPoints<span style="color: #008000;">&#40;</span>touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span>, touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #6666cc; font-weight: bold;">double</span> delta <span style="color: #008000;">=</span> angle <span style="color: #008000;">-</span> _previousAngle<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Value</span><span style="color: #008000;">;</span>
        Map<span style="color: #008000;">.</span><span style="color: #0000FF;">Heading</span> <span style="color: #008000;">-=</span> delta<span style="color: #008000;">;</span>
        _previousAngle <span style="color: #008000;">=</span> angle<span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span>
    <span style="color: #008000;">&#123;</span>
      _previousAngle <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
      _isRotating <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
      SuppressMapGestures <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span> AngleBetweenPoints<span style="color: #008000;">&#40;</span>TouchPoint p1, TouchPoint p2<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Atan2</span><span style="color: #008000;">&#40;</span>p1<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">-</span> p2<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span>, p1<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">-</span> p2<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">*</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">180</span> <span style="color: #008000;">/</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">PI</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Touch gestures are detected via the <code>Touch.FrameReported</code> event. When two fingers are placed on the screen the initial rotation angle is recorded. When the minimum rotation is exceeded, the <code>Map.Heading</code> is updated with each ‘delta’ reported. Really simple code, but a fantastic feature for the user!</p>
<h2>A Pitch Gesture</h2>
<p>You get a real feel for the vector-nature of the maps when you set the ‘pitch’, a style of rendering that is often used on satnavs.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/04/PitchGesture.jpg" alt="PitchGesture" width="282" height="483" class="aligncenter size-full wp-image-2407" /></p>
<p>I initially considered using a two finger pull-down gesture, which is similar to the one which Google Maps on Android uses, but found it very hard to coordinate the three gestures, zoom, rotate, pitch, which all use the same two-fingers! So instead, I opted for a three-finger pull-down gesture to increase the pitch of the map.</p>
<p>The code follows a very similar pattern to the rotate gesture:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Adds a three-finger pitch gesture to a Map control.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MapPitchGesture <span style="color: #008000;">:</span> MapGestureBase
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
  <span style="color: #008080; font-style: italic;">/// Gets or sets the sensitivity of this gesture</span>
  <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">double</span> Sensitivity <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">get</span><span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">set</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">?</span> _initialPitchYLocation<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> MapPitchGesture<span style="color: #008000;">&#40;</span>Map map<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">&#40;</span>map<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    Sensitivity <span style="color: #008000;">=</span> <span style="color: #FF0000;">0.5</span><span style="color: #008000;">;</span>
    Touch<span style="color: #008000;">.</span><span style="color: #0000FF;">FrameReported</span> <span style="color: #008000;">+=</span> Touch_FrameReported<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> Touch_FrameReported<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, TouchFrameEventArgs e<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">var</span> touchPoints <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTouchPoints</span><span style="color: #008000;">&#40;</span>Map<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    SuppressMapGestures <span style="color: #008000;">=</span> touchPoints<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>touchPoints<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>_initialPitchYLocation<span style="color: #008000;">.</span><span style="color: #0000FF;">HasValue</span><span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        _initialPitchYLocation <span style="color: #008000;">=</span> touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
      <span style="color: #008000;">&#125;</span>
&nbsp;
      <span style="color: #6666cc; font-weight: bold;">double</span> delta <span style="color: #008000;">=</span> touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">-</span> _initialPitchYLocation<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Value</span><span style="color: #008000;">;</span>
      <span style="color: #6666cc; font-weight: bold;">double</span> newPitch <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Min</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">75</span>, <span style="color: #008000;">&#40;</span>Map<span style="color: #008000;">.</span><span style="color: #0000FF;">Pitch</span> <span style="color: #008000;">+</span> delta <span style="color: #008000;">*</span> Sensitivity<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
      Map<span style="color: #008000;">.</span><span style="color: #0000FF;">Pitch</span> <span style="color: #008000;">=</span> newPitch<span style="color: #008000;">;</span>
      _initialPitchYLocation <span style="color: #008000;">=</span> touchPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span>
    <span style="color: #008000;">&#123;</span>
      _initialPitchYLocation <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>As soon as three fingers are placed on the screen, the gesture becomes active. The movement of the first finger is used to determine the delta to apply to the <code>Pitch </code>property. Again, nice and simple!</p>
<p>The sourcecode for these gesture, plus a demo app is <a href="https://github.com/ColinEberhardt/WP8-MapGestures">available via github</a>. Please let me know if you use this code in any of your apps.</p>
<p>Regards, Colin E. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2013/04/enhanced-windows-phone-8-map-gestures/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Comparing KendoUI and Knockout (with a bit of jQueryMobile on the side)</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2013/04/comparing-kendoui-and-knockout-with-a-bit-of-jquerymobile-on-the-side/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2013/04/comparing-kendoui-and-knockout-with-a-bit-of-jquerymobile-on-the-side/#comments</comments>
		<pubDate>Mon, 08 Apr 2013 10:43:31 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[codeproject]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=2380</guid>
		<description><![CDATA[TweetThis blog post compares the same twitter search application written with both Knockout and Kendo in order to highlight the strengths and weaknesses of each framework. Introduction I’ve always been a big fan of Knockout, most likely because it reminds me of Silverlight (rest in peace). For my thoughts on how Silverlight and Knockout compare, [...]]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton2380" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F04%2Fcomparing-kendoui-and-knockout-with-a-bit-of-jquerymobile-on-the-side%2F&amp;text=Comparing%20KendoUI%20and%20Knockout%20%28with%20a%20bit%20of%20jQueryMobile%20on%20the%20side%29&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F04%2Fcomparing-kendoui-and-knockout-with-a-bit-of-jquerymobile-on-the-side%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.scottlogic.co.uk/blog/colin/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>This blog post compares the same twitter search application written with both Knockout and Kendo in order to highlight the strengths and weaknesses of each framework.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/04/knockout-vs-kendo.png" alt="knockout-vs-kendo" width="400" height="175" class="aligncenter size-full wp-image-2402" /></p>
<h2>Introduction</h2>
<p>I’ve always been a big fan of Knockout, most likely because it reminds me of Silverlight (rest in peace).</p>
<blockquote><p>For my thoughts on how Silverlight and Knockout compare, head over to codeproject where I wrote <a href="http://www.codeproject.com/Articles/365120/KnockoutJS-vs-Silverlight">quite a lengthy article on the subject</a>.</p></blockquote>
<p>More recently I have been dabbling with the use of Knockout for writing mobile applications. Because Knockout is an MVVM framework and doesn’t have any UI components of its own, I used a combination of jQuery Mobile (jQM) and Knockout. I must admit, the integration of these two frameworks <a href="http://www.scottlogic.co.uk/blog/colin/2012/10/integrating-knockout-and-jquerymobile/">wasn’t entirely painless</a>!.</p>
<p>It is the integration pain I experienced with jQM and Knockout that has resulted in my interest in KendoUI. </p>
<p>KendoUI (<a href="http://www.kendoui.com/">www.kendoui.com</a>) is a commercial JavaScript framework that includes web and mobile UI widgets together with an MVVM framework, which, on initial inspection, closely resembles Knockout. The promise of an MVVM framework and mobile widgets that play nicely together is quite appealing!</p>
<p>In order to compare Kendo with Knockout + jQM I re-implemented the twitter-search application that <a href="http://www.scottlogic.co.uk/blog/colin/2012/10/integrating-knockout-and-jquerymobile/">I blogged about a few months ago</a>. The rest of this blog post is a collection of thoughts, commentary on the differences and personal opinions.</p>
<p>The two version of the code are available on github:</p>
<ul>
<li><a href="https://github.com/ColinEberhardt/Knockout-jQueryMobile">https://github.com/ColinEberhardt/Knockout-jQueryMobile</a></li>
<li><a href="https://github.com/ColinEberhardt/KendoUI-TwitterSearch">https://github.com/ColinEberhardt/KendoUI-TwitterSearch</a></li>
</ul>
<p>And you can see working examples at the following locations:</p>
<ul>
<li><a href="http://colineberhardt.github.io/Knockout-jQueryMobile/">Knockout + jQuery Mobile</a></li>
<li><a href="http://colineberhardt.github.io/KendoUI-TwitterSearch/">KendoUI</a></li>
</ul>
<p>It is worth viewing the above on your phone.</p>
<h2>From Knockout to KendoUI</h2>
<ul>
<li><a href="#magic_properties">Knockout has magic properties, Kendo has magic objects!</a></li>
<li><a href="#construction">Knockout is more flexible regarding view model construction</a></li>
<li><a href="#intellisense">Kendo requires a little effort to make it work with Intellisense</a></li>
<li><a href="#hierarchies">Knockout supports view model hierarchies</a></li>
<li><a href="#bindings">Kendo bindings are not JavaScript!</a></li>
<li><a href="#data">Kendo lacks a $data binding</a></li>
<li><a href="#widgets">Kendo has its own UI widgets</a>!</li>
<li><a href="#dom">Kendo UI does not mangle the DOM</a></li>
<li><a href="#styles">jQM has a more extensive set of styles</a></li>
<li><a href="themes">Kendo supports multiple mobile themes</a></li>
<li><a href="#datasource">Kendo has a datasource concept</a></li>
<li><a href="#money">Knockout is open source, Kendo costs $$$</a></li>
</ul>
<h3><a id="magic_properties"></a>Knockout has magic properties, Kendo has magic objects!</h3>
<p>JavaScript does not support the notion of change-notification when you change the value of an object’s properties. This is a vital feature for supporting binding within an MVVM framework, so both Kendo and Knockout have to provide this missing change notification.</p>
<p>With Knockout change notification is provided via observable properties:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> knockoutViewModel <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  name <span style="color: #339933;">:</span> ko.<span style="color: #660066;">observable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;john&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>When a property has been created via <code>ko.observable</code> you can subscribe to change notifications for that property.</p>
<p>With Kendo change notification is provided via observable objects:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> kendoViewModel <span style="color: #339933;">=</span> kendo.<span style="color: #660066;">observable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  name <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;john&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And as a result you can subscribe to change notifications on the object..</p>
<p>Neither Kendo or Knockout are able to detect when a property is set directly, instead, you must set the property value via a function. With Knockout, your property is actually a function which you can set as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">knockoutViewModel.<span style="color: #660066;">name</span><span style="color: #009900;">&#40;</span>“john smith”<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span></pre></td></tr></table></div>

<p>Whereas with Kendo you set the property via the owning object:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">kendoViewModel.<span style="color: #000066; font-weight: bold;">set</span><span style="color: #009900;">&#40;</span>“name”<span style="color: #339933;">,</span> “john smith”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Both Kendo and Knockout support the concept of dependant properties, where you construct a property by composing one or more of the other objects properties, with change notifications happening automatically.</p>
<p>Both Kendo’s object-centic and Knockout’s property-centric approaches seem quite reasonable, but as we shall see later this small difference has an impact on many aspects of each framework.</p>
<h3><a id="construction"></a>Knockout is more flexible regarding view model construction</h3>
<p>Because Knockout performs its ‘magic’ at the property level, it does not place any restrictions on the way in which you construct your view models. You can use the literal syntax:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> knockoutViewModel <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  name <span style="color: #339933;">:</span> ko.<span style="color: #660066;">observable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;john&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Or define a constructor:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> KnockoutViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">name</span> <span style="color: #339933;">=</span> ko.<span style="color: #660066;">observable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;john&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">var</span> viewModel <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> KnockoutViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Personally I like the second approach because it gives you a view model ‘factory’, i.e. you can create multiple instances of the same view model, and it also allows you to define both public and private functions:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> KnockoutViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">name</span> <span style="color: #339933;">=</span> ko.<span style="color: #660066;">observable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;john&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  saveState <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// do something here</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    saveState<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the code above the <code>saveState </code>function is private – for more information on this pattern I&#8217;d recommend reading <a href="http://javascript.crockford.com/private.html">Private Members in JavaScript</a> by Douglas Crockford.</p>
<p>All of the Kendo examples create view model using a literal syntax:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">var</span> kendoViewModel <span style="color: #339933;">=</span> kendo.<span style="color: #660066;">observable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  name <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;john&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Initially I was under the impression that it wasn’t possible to create Kendo view models using constructor functions, furthermore, one of the nice guys from the Kendo support rather <a href="http://www.kendoui.com/forums/framework/mvvm/can-you-create-view-models-as-functions-.aspx">apologetically told me</a> “I am afraid that it is not possible to emulate Knockout style of view model creation via functions. Kendo MVVM supports only the literal style.”.</p>
<p>However, after a little bit of thought, I realised that it is possible if you explicitly return an observable as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> KendoViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">name</span> <span style="color: #339933;">=</span> “john”<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> kendo.<span style="color: #660066;">observable</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">var</span> viewModel <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> KendoViewModel <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>However, things are not quite so straightforward – if you need to capture the reference to ‘this’ you must ensure that the reference is to the observable object, as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">function</span> KendoViewModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">name</span> <span style="color: #339933;">=</span> “john”<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">function</span> saveState <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>that<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">update</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    saveState<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">var</span> that <span style="color: #339933;">=</span> kendo.<span style="color: #660066;">observable</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> that<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">var</span> viewModel <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> KendoViewModel <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In the above code the variable, <code>that</code>, is always going to refer to the observable object regardless of what, <code>this</code>, refers to.</p>
<h3><a id="intellisense"></a>Kendo requires a little effort to make it work with Intellisense</h3>
<p>Following on from the previous point, because the Kendo ‘magic’ is at the object level, Visual Studio Intellisense becomes flummoxed. Now I know that Visual Studio is perhaps not the best tool for JavaScript, but I can bet that quite a few Knockout and Kendo developers use it!</p>
<p>Visual Studio uses pseudo-execution of your JavaScript code to provide Intellisense. With Knockout this works well out-of-the-box &#8211; see the image below where the update function, together with its ‘summary’ text, are picked up by Intellisense:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/04/ko_intellisense.png" alt="ko_intellisense" width="424" height="407" class="aligncenter size-full wp-image-2382" /></p>
<p>Whereas with Kendo, in order for Visual Studio to be able to execute your code it needs to be aware of the Kendo and jQuery JavaScript files. This can be done by adding a ‘reference’ comment, as shown below:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/04/kendo_intellisense.png" alt="kendo_intellisense" width="475" height="448" class="aligncenter size-full wp-image-2383" /></p>
<p>Note that you can also see the other functions that are present on observable objects.</p>
<h3><a id="hierarchies"></a>Knockout supports view model hierarchies</h3>
<p>One particularly elegant feature of Knockout is that it supports view model hierarchies. When binding collections of objects, Knockout creates a child binding context that refers to the nested view model data. You can also explicitly set the binding-context of an element via the ‘with’ binding. This approach allows you to create complex nested view models.</p>
<p>With Kendo, when binding a collection of objects the ‘context’ for each item is the parent view model, which means that any event bindings are sent to the owning view model. This is clearly due to the way that Kendo uses observable objects rather than observable properties.</p>
<p>Whilst this is not a significant limitation, I do miss the binding-context concept when working with Kendo. The lack of this feature does mean that view models can become bloated.</p>
<h3><a id="bindings"></a>Kendo bindings are not JavaScript!</h3>
<p>With Knockout, bindings are JavaScript, which means you can have bindings which contain logic. For example:</p>
<pre>
data-bind="enable: searchTerm().length > 0 && isSearching() == false,
           click: search"
</pre>
<p>Kendo bindings are not JavaScript!</p>
<p>A simple way to achieve equivalent functionality is to move the JavaScript in the binding into a dependant property:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">searchButtonDisabled<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066; font-weight: bold;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;searchTerm&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066; font-weight: bold;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;isSearching&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Which is bound as follows:</p>
<pre>
data-bind="click: executeSearch, { disabled: searchButtonDisabled }"
</pre>
<p>I do not see this as a significant limitation of Kendo. I do use this feature quite often with Knockout, it feels a little like the Silverlight / WPF concept of value-converters. However, I can see how it could be abused, hiding JavaScript logic within bindings isn’t terribly good for testing or maintenance!</p>
<h3><a id="data"></a>Kendo lacks a $data binding</h3>
<p>With Knockout, if you create a ‘foreach’ binding to an array of strings, the template that renders each string can make use of the <code>$data</code> binding:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">data-bind</span>=<span style="color: #ff0000;">&quot;text: $data&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The above is needed because the binding-context of the above span element is a string – we want to bind to the object itself rather than a property of the object.</p>
<p>I could not find an equivalent feature with Kendo, so had to create an object as a container for the string:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">recentSearches</span>.<span style="color: #660066;">unshift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> searchString<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">searchTerm</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And bind it as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">data-bind</span>=<span style="color: #ff0000;">&quot;text:searchString&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Again, a pretty minor limitation.</p>
<h3><a id="widgets"></a>Kendo has its own UI widgets!</h3>
<p>So far much of my discussion has focussed on Knockout features which Kendo does not support. However, Kendo is much more than just an MVVM framework, it includes a large number of web and mobile UI widgets.</p>
<p>In the context of this comparison, I integrated jQM with Knockout to create my mobile UI – and as I mentioned earlier, <a href="http://www.scottlogic.co.uk/blog/colin/2012/10/integrating-knockout-and-jquerymobile/">this integration was pretty painful</a>. In contrast, the Kendo UI Mobile framework integrates seamlessly with the Kendo MVVM framework – as you might expected!</p>
<h3><a id="dom"></a>Kendo UI does not mangle the DOM</h3>
<p>While we are on the subject of the UI, one of the features of jQM that I really disliked is the way that it totally mangles the DOM.</p>
<p>In order to support the jQM styling it requires a large number of ‘supporting’ elements. As an example a button is transformed from this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">data-bind</span>=<span style="color: #ff0000;">&quot;enable: isSearchEnabled,</span>
<span style="color: #009900;">                                 click: executeSearch&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Go<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>To this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ui-btn ui-btn-inline ui-btn-corner-all ui-shadow ui-btn-up-c&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ui-btn-inner ui-btn-corner-all&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ui-btn-text&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Go<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ui-btn-hidden&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Go&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">data-bind</span>=<span style="color: #ff0000;">&quot;enable: isSearchEnabled, </span>
<span style="color: #009900;">                                    click: executeSearch&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This causes all kinds of headaches when trying to use jQM with an MVVM or MVC framework. </p>
<p>In contrast, with Kendo when you create a button:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">data-role</span>=<span style="color: #ff0000;">&quot;button&quot;</span> </span>
<span style="color: #009900;">   <span style="color: #000066;">data-bind</span>=<span style="color: #ff0000;">&quot;click: executeSearch, { disabled: searchButtonDisabled }&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Go<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>It adds very little supporting structure:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">data-role</span>=<span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot; km-button&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">data-bind</span>=<span style="color: #ff0000;">&quot;click: executeSearch, { disabled: searchButtonDisabled }&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;km-text&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Go<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>And in many cases it leaves the DOM structure unaltered. </p>
<h3><a id="styles"></a>jQM has a more extensive set of styles</h3>
<p>The jQuery Mobile framework is more extensive than Kendo. As a quick example, jQM nicely styles your list items:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/04/jqm_list.png" alt="jqm_list" width="425" height="276" class="aligncenter size-full wp-image-2385" /></p>
<p>With Kendo, you have to put in a bit of extra effort to style the list:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/04/kendo_list.png" alt="kendo_list" width="422" height="447" class="aligncenter size-full wp-image-2384" /></p>
<p>This is just one example of many – jQM is a <em>big</em> framework.</p>
<h3><a id="themes"></a>Kendo supports multiple mobile themes</h3>
<p>The jQM UI is designed to look at home on iOS devices, which is just fine for the ~30% of people who own an iPhone. However, this UI just looks plain wrong on an Android or Windows Phone. </p>
<p>There are a few open source Android themes for jQM, but I didn’t get a satisfactory result with any of them. Also, Microsoft have <a href="http://www.scottlogic.co.uk/blog/colin/2012/04/introducing-the-jquery-mobile-metro-theme/">contributed a Metro theme to jQM, but it is rather ugly</a>!</p>
<p>In contrast, Kendo supports iOS, Android, BlackBerry and Windows Phone, <a href="http://demos.kendoui.com/mobile/overview/index.html#/">as shown on their online demo</a>. This is pretty neat!</p>
<h3><a id="datasource"></a>Kendo has a datasource concept</h3>
<p>With the Knockout + jQM application I wrote a very simple <code>TwitterSearchService</code> which acts as a datasource. The Kendo framework has a <a href="http://docs.kendoui.com/getting-started/framework/datasource/overview"><code>DataSource</code> component</a> which makes integrating with services such as Twitter much easier, you typically provide configuration to the <code>DataSource </code>and it does the rest. Also, the UI components like the <code>ListView </code>integrate directly with the <code>DataSource</code>, with features like pull-to-load-more available out-of-the-box.</p>
<h3><a id="money"></a>Knockout is open source, Kendo costs $$$</h3>
<p>This one is pretty obvious really …</p>
<p>Knockout is open source, and as a result doesn’t cost you anything to use it. For an open source project it is very well documented and there are many blog posts that provide tutorials and solutions to problems. The <a href="http://learn.knockoutjs.com/">interactive tutorial</a> is a particularly fantastic idea.</p>
<p>Kendo will cost you a few hundred dollars to buy (http://www.kendoui.com/purchase.aspx). Considering that Kendo is a UI widget framework, MVVM framework and mobile framework, I would say that the price is very reasonable. Also, the documentation is of a similar quantity and quality to that of Knockout.</p>
<h2>Conclusions</h2>
<p>This article has been a mixed-bag of observations, thoughts and opinions and it is not intended to be an exhaustive comparison. Despite that, I hope it will be useful for others.</p>
<p>I certainly prefer the Knockout implementation of MVVM, I find it more powerful and flexible than the Kendo equivalent. However, Kendo’s MVVM framework is certainly adequate.</p>
<p>When it comes to building mobile applications, the fully integrated Kendo solution has some pretty big advantages over Knockout and jQuery Mobile.</p>
<p>Regards, Colin E.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2013/04/comparing-kendoui-and-knockout-with-a-bit-of-jquerymobile-on-the-side/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>HTML5 – It Just Got Real – A One-day Conference in London 14th May</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2013/03/html5-it-just-got-real-a-one-day-conference-in-london-14th-may/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2013/03/html5-it-just-got-real-a-one-day-conference-in-london-14th-may/#comments</comments>
		<pubDate>Thu, 28 Mar 2013 14:04:57 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=2375</guid>
		<description><![CDATA[TweetAnnouncing a one-day conference at the Royal Society, London UK, on the 14th of May. Just a few years back I wrote a white paper titled “Flex, Silverlight or HTML5? Time to decide …” with the help of a couple of my colleagues, comparing the strengths and weaknesses of the three competing technologies. This paper [...]]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton2375" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F03%2Fhtml5-it-just-got-real-a-one-day-conference-in-london-14th-may%2F&amp;text=HTML5%20%E2%80%93%20It%20Just%20Got%20Real%20%E2%80%93%20A%20One-day%20Conference%20in%20London%2014th%20May&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F03%2Fhtml5-it-just-got-real-a-one-day-conference-in-london-14th-may%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.scottlogic.co.uk/blog/colin/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p><em>Announcing a one-day conference at the Royal Society, London UK, on the 14th of May.</em></p>
<p><a href="http://html5-it-just-got-real.com/"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/03/html5-just-got-real.png" alt="html5-just-got-real" width="495" height="269" class="aligncenter size-full wp-image-2376" /></a></p>
<p>Just a few years back I wrote a white paper titled <a href="http://www.scottlogic.co.uk/blog/colin/2011/05/flex-silverlight-html5-time-to-decide/">“Flex, Silverlight or HTML5? Time to decide …”</a> with the help of a couple of my colleagues, comparing the strengths and weaknesses of the three competing technologies. This paper was aimed at helping developers make an informed choice when faced with developing an interactive web site or complex web app.</p>
<p>Don’t bother reading that white paper now!  It was only written two years ago, but is now so out-of-date that it might as well have been written ten years ago.</p>
<p>Here’s the penultimate paragraph:</p>
<blockquote><p>“It is very difficult to predict where we will be in a few years’ time and whether there will be some technology casualties along the way. Can all three technologies co-exist? Or will one or more be relegated to the internet history books like Java Applets and ActiveX?”</p></blockquote>
<p>Yes, there have been some casualties, <a href="http://www.scottlogic.co.uk/blog/colin/2011/11/the-untimely-demise-of-the-plugin-and-how-lob-developments-will-suffer/">both Silverlight … and Flex</a>!</p>
<p>The rise of smartphones and tablets has accelerated HTML5 adoption to the point where plugins are considered a legacy technology. Invest in them at your peril!</p>
<p>The problem is that enterprise-scale HTML5 development is far from easy. With Flex and Silverlight you have the comfort of working within a shrink-wrapped development environment, whereas HTML5 is like the Wild West; assembling a workable set of tools, framework and processes is not an easy task.</p>
<p>This is why we decided to stage our own conference – we want to talk about the challenges of enterprise scale HTML5 development, and how to tackle them.</p>
<p>If you are interested, and are thinking of signing up, take a look at the conference website &#8211; <a href="http://html5-it-just-got-real.com/">html5-it-just-got-real.com</a> – there will be talks on a range of subjects, ranging from practical and insightful to radical and fun (we have a BBC presenter and a guitar-wielding JavaScript rockstar). </p>
<p>Regards, Colin E.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2013/03/html5-it-just-got-real-a-one-day-conference-in-london-14th-may/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Windows Phone 8 Running App Article wins CodeProject competition</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2013/02/windows-phone-8-running-app-article-wins-codeproject-competition/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2013/02/windows-phone-8-running-app-article-wins-codeproject-competition/#comments</comments>
		<pubDate>Mon, 25 Feb 2013 09:01:44 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[codeproject]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=2368</guid>
		<description><![CDATA[TweetI&#8217;ve just received an email from those nice folks at CodeProject letting me know that my article A Windows Phone 8 Run Tracking App in 100 Lines of Code has just won the Best Mobile article of January 2013 award. I must admit, this one was a bit of a surprise. I put this article [...]]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton2368" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F02%2Fwindows-phone-8-running-app-article-wins-codeproject-competition%2F&amp;text=Windows%20Phone%208%20Running%20App%20Article%20wins%20CodeProject%20competition&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F02%2Fwindows-phone-8-running-app-article-wins-codeproject-competition%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.scottlogic.co.uk/blog/colin/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>I&#8217;ve just received an email from those nice folks at CodeProject letting me know that my article <a href="http://www.codeproject.com/Articles/521530/A-Windows-Phone-8-Run-Tracking-App-in-100-Lines-of">A Windows Phone 8 Run Tracking App in 100 Lines of Code</a> has just won the <em>Best Mobile article of January 2013</em> award. </p>
<p><a href="http://www.codeproject.com/Articles/521530/A-Windows-Phone-8-Run-Tracking-App-in-100-Lines-of"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2013/02/WP8RunnerScreenshot.png" alt="WP8RunnerScreenshot" width="500" height="405" class="aligncenter size-full wp-image-2369" /></a></p>
<p>I must admit, this one was a bit of a surprise. I put this article together very quickly for the <a href="http://www.developer.nokia.com/Community/Wiki/Windows_Phone_8_Wiki_Competition_2012Q4">Nokia Wiki Competition</a>  &#8230; which I didn&#8217;t win. The article is quite brief, and the app that it described is very simple &#8211; this is in contrast to my usual articles on CodeProject, which are often quite lengthy. Judging from the comments, it looks like people really like these short, but focused articles. I might do a few more of these in future! (they are certainly less effort <img src='http://www.scottlogic.co.uk/blog/colin/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' />  )</p>
<p>Colin E.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2013/02/windows-phone-8-running-app-article-wins-codeproject-competition/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linq to Objective-C</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2013/02/linq-to-objective-c/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2013/02/linq-to-objective-c/#comments</comments>
		<pubDate>Fri, 15 Feb 2013 09:10:03 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[codeproject]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=2358</guid>
		<description><![CDATA[TweetIn the past few months I have been immersing myself into the world of iOS development. Whilst the Objective-C language takes a little getting used to, with its odd syntax and memory management rules, it is certainly a fun platform to develop for. I do miss a few C# language features, such as events, but [...]]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton2358" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F02%2Flinq-to-objective-c%2F&amp;text=Linq%20to%20Objective-C&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F02%2Flinq-to-objective-c%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.scottlogic.co.uk/blog/colin/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>In the past few months I have been immersing myself into the world of iOS development. Whilst the Objective-C language takes a little getting used to, with its odd syntax and memory management rules, it is certainly a fun platform to develop for. I do miss a few C# language features, such as events, but for the most part I am a happy iOS developer.</p>
<p>… that is apart from Linq!</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/03/tree.jpg" alt="tree" width="650" height="201" class="aligncenter size-full wp-image-608" /></p>
<p>A few weeks back I was writing some examples for a future release of the <a href="http://www.shinobicontrols.com/">ShinobiControls Grid</a>. The example in question required a datasource of people grouped by the first letter of their surname. Despite the use of predicates and key valued sorting, the code looked like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> createGroupedTestData
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableArray</span><span style="color: #002200;">*</span> groupedData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// create some people</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> people <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>PersonDataSource generatePeople<span style="color: #002200;">:</span><span style="color: #2400d9;">50</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// create a set of letters - based on the first letter of the surname</span>
    <span style="color: #400080;">NSMutableSet</span><span style="color: #002200;">*</span> groups <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableSet</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>PersonDataObject<span style="color: #002200;">*</span> person <span style="color: #a61390;">in</span> people<span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>groups addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>person.surname substringToIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// create the groups</span>
    <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span> letter <span style="color: #a61390;">in</span> groups<span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        PersonGroup<span style="color: #002200;">*</span> group <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>PersonGroup alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
        group.letter <span style="color: #002200;">=</span> letter;
&nbsp;
        <span style="color: #11740a; font-style: italic;">// locate the person objects that belong in this group</span>
        <span style="color: #400080;">NSPredicate</span><span style="color: #002200;">*</span> predicate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSPredicate</span> predicateWithBlock<span style="color: #002200;">:^</span>BOOL<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> evaluatedObject, <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>bindings<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            PersonDataObject<span style="color: #002200;">*</span> person <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>PersonDataObject<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>evaluatedObject;
            <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>person.surname substringToIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span> isEqualToString<span style="color: #002200;">:</span>letter<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
        group.items <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>people filteredArrayUsingPredicate<span style="color: #002200;">:</span>predicate<span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #002200;">&#91;</span>groupedData addObject<span style="color: #002200;">:</span>group<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// sort the groups</span>
    <span style="color: #400080;">NSSortDescriptor</span><span style="color: #002200;">*</span> sortDescriptor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSSortDescriptor</span> alloc<span style="color: #002200;">&#93;</span> initWithKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;letter&quot;</span> ascending<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> sortedGroupedData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>groupedData sortedArrayUsingDescriptors<span style="color: #002200;">:</span>@<span style="color: #002200;">&#91;</span>sortDescriptor<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> sortedGroupedData;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>That’s a pretty unwieldy lump in my opinion. With Linq I am used to performing this sort of logic with a single query!</p>
<p>So, I decided to go ahead and implement a bunch of Linq methods for Objective-C, which results in a much cleaner implementation:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> createGroupedTestData
<span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// create some people</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> people <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>PersonDataSource generatePeople<span style="color: #002200;">:</span><span style="color: #2400d9;">50</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    Selector firstLetterOfSurname <span style="color: #002200;">=</span> <span style="color: #002200;">^</span>id<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> person<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>person surname<span style="color: #002200;">&#93;</span> substringToIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>;
&nbsp;
    Selector groupForLetter <span style="color: #002200;">=</span> <span style="color: #002200;">^</span>id<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> letter<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        PersonGroup<span style="color: #002200;">*</span> group <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>PersonGroup alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
        group.letter <span style="color: #002200;">=</span> letter;
        group.items <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>people where<span style="color: #002200;">:^</span>BOOL<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> person<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>person surname<span style="color: #002200;">&#93;</span> substringToIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span> isEqualToString<span style="color: #002200;">:</span>letter<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">return</span> group;
    <span style="color: #002200;">&#125;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>people   select<span style="color: #002200;">:</span>firstLetterOfSurname<span style="color: #002200;">&#93;</span>
                        sort<span style="color: #002200;">&#93;</span>
                        distinct<span style="color: #002200;">&#93;</span>
                        select<span style="color: #002200;">:</span>groupForLetter<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Not only is the above code more concise, which is nearly always a good thing (unless you are talking regex-concise!), it is also much more readable. The ‘select, distinct, sort, select’ query makes it much easier to determine what the resulting output of this code will be.</p>
<p>In this blog post I’ll explain what Linq is (for those of you who have not heard of it before), and how I implemented Linq-to-Objective-C. If you just want to use the code, you can <a href="https://github.com/ColinEberhardt/LinqToObjectiveC">grab a copy from github</a>.</p>
<h2>An introduction to Linq</h2>
<p>If you are a seasoned .NET developer, you can skip this section, however, if you have not heard of Linq before, then read on …</p>
<p>Linq was added to the C# language back in 2007. The name ’linq’ stands for Language Integrated Query, and as the name implies, its original aim was to more tightly integrate queries into the C# language. As an example, when querying database developers find themselves writing queries using SQL statements embedded within literal strings:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="" style="font-family:monospace;">string query = “SELECT * FROM Person WHERE age &lt; <span style="">10</span>”</pre></td></tr></table></div>

<p>The problem with the above code is that the SQL statements are not checked by the compiler, and as a result, errors will only surface at runtime. This is not a problem that is peculiar to C# &#8211; you will find SQL statements embedded within strings in virtually every language.</p>
<p>With Linq queries are no longer literal strings, they are instead constructed using keywords that are part of the C# language itself:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">var</span> query <span style="color: #008000;">=</span>  <span style="color: #0600FF; font-weight: bold;">from</span> p <span style="color: #0600FF; font-weight: bold;">in</span> PersonCollection
               <span style="color: #0600FF; font-weight: bold;">where</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">age</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10</span>
               <span style="color: #0600FF; font-weight: bold;">select</span> p<span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>This allows the compiler to check your query syntax, resulting in less error prone code.</p>
<p>C# provides a couple of different syntaxes for Linq, the query syntax, shown above – and the fluent syntax, where method invocations are chained together. </p>
<p>The two are functionally equivalent:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">var</span> query <span style="color: #008000;">=</span>  <span style="color: #0600FF; font-weight: bold;">from</span> p <span style="color: #0600FF; font-weight: bold;">in</span> PersonCollection
               <span style="color: #0600FF; font-weight: bold;">where</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">age</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10</span>
               <span style="color: #0600FF; font-weight: bold;">select</span> p<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">var</span> query <span style="color: #008000;">=</span> PersonCollection<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">age</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Whilst the application of Linq for querying database is obvious, Linq can be used to query practically anything. The .NET framework supplies Linq to SQL, XML and Objects – while the community has added Linq to CSV, JSON, DataSets, Facebook, and my own contribution <a href="http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree/">Linq-to-VisualTree</a>.</p>
<p>I’ve found myself using Linq in virtually every .NET application I have ever written – and I miss it!</p>
<p>Fortunately the ~25 different Linq extensions methods are actually quite easy to implement, as the C# guru Jon Skeet demonstrated in an <a href="http://msmvps.com/blogs/jon_skeet/archive/2011/02/23/reimplementing-linq-to-objects-part-45-conclusion-and-list-of-posts.aspx">epic series of blog posts</a>. So, why not bring this API to Objective-C?</p>
<h2>Linq to Objective-C</h2>
<p>In this section I’ll rattle through the implementation of a number of Linq methods, for the full set, <a href="https://github.com/ColinEberhardt/LinqToObjectiveC">head to github</a>.</p>
<h3>Where</h3>
<p>The Linq ‘where’ method filters an array of objects based on a predicate that returns true for any object that should be included in the output array. Using a block for the predicate, gives the following method signature:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">typedef</span> <span style="color: #a61390;">BOOL</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span>Predicate<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">/** Filters a sequence of values based on a predicate.
&nbsp;
 @param The function to test each source element for a condition.
 @return The elements from the input sequence that satisfy the condition.
 */</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> where<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Predicate<span style="color: #002200;">&#41;</span>predicate;</pre></td></tr></table></div>

<p>Before diving straight into the implementation, I’ll demonstrate its usage via a unit test. Given the following array of Person objects:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> createTestData
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> @<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Person personWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span> age<span style="color: #002200;">:</span>@25<span style="color: #002200;">&#93;</span>,
    <span style="color: #002200;">&#91;</span>Person personWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;frank&quot;</span> age<span style="color: #002200;">:</span>@45<span style="color: #002200;">&#93;</span>,
    <span style="color: #002200;">&#91;</span>Person personWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ian&quot;</span> age<span style="color: #002200;">:</span>@35<span style="color: #002200;">&#93;</span>,
    <span style="color: #002200;">&#91;</span>Person personWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;jim&quot;</span> age<span style="color: #002200;">:</span>@25<span style="color: #002200;">&#93;</span>,
    <span style="color: #002200;">&#91;</span>Person personWithName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;joe&quot;</span> age<span style="color: #002200;">:</span>@55<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Where <code>Person </code>is a simple object with <code>name </code>and <code>age </code>properties. The test I created for the where method is as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testWhere
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> input <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self createTestData<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> peopleWhoAre25 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>input where<span style="color: #002200;">:^</span>BOOL<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> person<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>person age<span style="color: #002200;">&#93;</span> isEqualToNumber<span style="color: #002200;">:</span>@25<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    STAssertEquals<span style="color: #002200;">&#40;</span>peopleWhoAre25.count, 2U, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;There should have been 2 items returned&quot;</span><span style="color: #002200;">&#41;</span>;
    STAssertEquals<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>peopleWhoAre25<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span> name<span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Bob is 25!&quot;</span><span style="color: #002200;">&#41;</span>;
    STAssertEquals<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>peopleWhoAre25<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span> name<span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;jim&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Jim is 25!&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Which simply tests that the simple where query successfully returns all <code>Person </code>instances with an age of 25.</p>
<p>The implementation of where is really quite trivial:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>where<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Predicate<span style="color: #002200;">&#41;</span>predicate
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableArray</span><span style="color: #002200;">*</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> item <span style="color: #a61390;">in</span> self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
       <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>predicate<span style="color: #002200;">&#40;</span>item<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
           <span style="color: #002200;">&#91;</span>result addObject<span style="color: #002200;">:</span>item<span style="color: #002200;">&#93;</span>;
       <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> result;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>We’re off to a good start!</p>
<p>So, how does this compare to the existing Objective-C APIs? Through the use of predicates it is quite easy to perform the same ‘people who are 25’ query. You can use block syntax:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSPredicate</span><span style="color: #002200;">*</span> predicate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSPredicate</span> predicateWithBlock<span style="color: #002200;">:^</span>BOOL<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> person, <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>bindings<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>person age<span style="color: #002200;">&#93;</span> isEqualToNumber<span style="color: #002200;">:</span>@25<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> peopleWhoAre25 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>input filteredArrayUsingPredicate<span style="color: #002200;">:</span>predicate<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>Or the more concise string-based predicates:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> peopleWhoAre25 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>input filteredArrayUsingPredicate<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSPredicate</span> predicateWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;age=25&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>With the Objective-C support for predicates, this Linq-style where method might not be the most useful, but the others are more interesting.</p>
<h3>Select</h3>
<p>The Linq ‘select’ method allows you to perform transformation, which is known as a projection. Each element is acted upon by a selector function, with the returned result being used to populate the output sequence. Here’s the method signature:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">typedef</span> <span style="color: #a61390;">id</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span>Selector<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">/** Projects each element of a sequence into a new form.
&nbsp;
 @param selector Projects each element of a sequence into a new form.
 @return An array whose elements are the result of invoking the transform function on each element of source.
 */</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> select<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Selector<span style="color: #002200;">&#41;</span>selector;</pre></td></tr></table></div>

<p>Again, I’ll demonstrate the using via a unit test. This example uses the select method to extract the <code>name </code>property for each person objects in the source array:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testSelect
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> input <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self createTestData<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> names <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>input select<span style="color: #002200;">:^</span>id<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> person<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>person name<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    STAssertEquals<span style="color: #002200;">&#40;</span>names.count, 5U, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #11740a; font-style: italic;">// 'spot' check a few values</span>
    STAssertEquals<span style="color: #002200;">&#40;</span>names<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEquals<span style="color: #002200;">&#40;</span>names<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;joe&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Again, the implementation is really quite simple:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>select<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Selector<span style="color: #002200;">&#41;</span>selector
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableArray</span><span style="color: #002200;">*</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> item <span style="color: #a61390;">in</span> self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>result addObject<span style="color: #002200;">:</span>selector<span style="color: #002200;">&#40;</span>item<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> result;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h3>Sort</h3>
<p>Linq doesn’t actually have a sort method, instead it provides <code>OrderBy</code> and <code>ThenBy</code> methods. Because I don’t want to get into multi-property sorting, I’ll substitute both of these for a single ‘sort’ function.</p>
<p>/** Sorts the elements of a sequence in ascending order.</p>
<p> @return An array whose elements are sorted in ascending order.<br />
 */<br />
- (NSArray*) sort;</p>
<p>/** Sorts the elements of a sequence in ascending order by using a specified keySelector.</p>
<p> @param keySelector A selector that provides the &#8216;key&#8217; which the array should by sorted by.<br />
 @return An array whose elements are sorted in ascending order.<br />
 */<br />
- (NSArray*) sort:(Selector)keySelector;</p>
<p>The first method simply sorts the array by invoking the compare method on each object. The second uses a selector to extract the key that is then used for the comparison.</p>
<p>The unit tests are as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testSort
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> input <span style="color: #002200;">=</span> @<span style="color: #002200;">&#91;</span>@21, @34, @25<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> sortedInput <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>input sort<span style="color: #002200;">&#93;</span>;
&nbsp;
    STAssertEquals<span style="color: #002200;">&#40;</span>sortedInput.count, 3U, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>sortedInput<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>, @21, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>sortedInput<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>, @25, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>sortedInput<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>, @34, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testSortWithKeySelector
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> input <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self createTestData<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> sortedByName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>input sort<span style="color: #002200;">:^</span>id<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> person<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>person name<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    STAssertEquals<span style="color: #002200;">&#40;</span>sortedByName.count, 5U, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEquals<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>sortedByName<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span> name<span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEquals<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>sortedByName<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span> name<span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;frank&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEquals<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>sortedByName<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span> name<span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ian&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEquals<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>sortedByName<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span> name<span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;jim&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEquals<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>sortedByName<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span> name<span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;joe&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>As you can see, one simply sorts an array of <code>NSNumber </code>instances, whereas the other sorts an array of <code>People</code> instances via the name property using the key selector.</p>
<p>The implementation is as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sort<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Selector<span style="color: #002200;">&#41;</span>keySelector
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self sortedArrayUsingComparator<span style="color: #002200;">:^</span>NSComparisonResult<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> obj1, <span style="color: #a61390;">id</span> obj2<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">id</span> valueOne <span style="color: #002200;">=</span> keySelector<span style="color: #002200;">&#40;</span>obj1<span style="color: #002200;">&#41;</span>;
        <span style="color: #a61390;">id</span> valueTwo <span style="color: #002200;">=</span> keySelector<span style="color: #002200;">&#40;</span>obj2<span style="color: #002200;">&#41;</span>;
        NSComparisonResult result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>valueOne compare<span style="color: #002200;">:</span>valueTwo<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">return</span> result;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sort
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self sort<span style="color: #002200;">:^</span>id<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> item<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> <span style="color: #a61390;">return</span> item;<span style="color: #002200;">&#125;</span> <span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>The sort-with-keySelector method makes use of the <code>NSArray</code> sort method that sorts via the result returned by a block. The ‘natural’ sort simply uses an identity selector in order to re-use the same implementation.</p>
<h3>OfType</h3>
<p>The Linq of-type method is use to filter a list of objects to remove all of those which are not of a specific type. Here’s the method signature:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/** Filters the elements of an an array based on a specified type.
&nbsp;
 @param type The type to filter the elements of the sequence on.
 @return An array whose elements are all of the given type.
 */</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> ofType<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">Class</span><span style="color: #002200;">&#41;</span>type;</pre></td></tr></table></div>

<p>And here is the associated test:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testOfType
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> mixed <span style="color: #002200;">=</span> @<span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;foo&quot;</span>, @25, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bar&quot;</span>, @33<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> strings <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>mixed ofType<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    STAssertEquals<span style="color: #002200;">&#40;</span>strings.count, 2U, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>strings<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;foo&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>strings<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bar&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Which filters out the <code>NSString </code>instances from a mixed array.</p>
<p>The implementation is quite trivial, making use of the where method which was detailed above:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ofType<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">Class</span><span style="color: #002200;">&#41;</span>type
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self where<span style="color: #002200;">:^</span>BOOL<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> item<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>item class<span style="color: #002200;">&#93;</span> isSubclassOfClass<span style="color: #002200;">:</span>type<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>The <code>ofType </code>method is quite useful for tasks such as finding all the subviews of a <code>UIView </code>that are of a specific type.</p>
<h3>Distinct</h3>
<p>The distinct method returns the distinct elements from an array, in other words, it removes duplicates based on an equality comparison. The signature is as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/** Returns distinct elements from a sequence.
&nbsp;
 @return An array of distinct elements.
 */</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> distinct;</pre></td></tr></table></div>

<p>The unit test is as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testDistinct
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> names <span style="color: #002200;">=</span> @<span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bill&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;brian&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> distinctNames <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>names distinct<span style="color: #002200;">&#93;</span>;
&nbsp;
    STAssertEquals<span style="color: #002200;">&#40;</span>distinctNames.count, 3U, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>distinctNames<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bill&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>distinctNames<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;brian&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>distinctNames<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>The implementation uses an <code>NSMutableArray </code>to construct an array of unique objects:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>distinct
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableArray</span><span style="color: #002200;">*</span> distinctSet <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> item <span style="color: #a61390;">in</span> self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>distinctSet containsObject<span style="color: #002200;">:</span>item<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>distinctSet addObject<span style="color: #002200;">:</span>item<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> distinctSet;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Note that the use of <code>containsObject </code>on an <code>NSMutableArray </code>is a potential performance issue for large arrays of data. A better method might make use of an <code>NSSet </code>which uses the object’s hash in order to more quickly determine whether an item is already contained within a set.</p>
<h3>Select Many</h3>
<p>The Linq select-many method is projection where the selector returns an array of objects. The select-many function flattens the returned arrays into a single array. For a <a href="http://www.codethinked.com/a-visual-look-at-the-linq-selectmany-operator">good visual explanation of select-many check out this blog post</a>.</p>
<p>Here is the method signature:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/** Projects each element of a sequence to an NSArray and flattens the resulting sequences into one sequence.
&nbsp;
 @param transform A transform function to apply to each element, this should return an NSArray.
 @return An array whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.
 */</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> selectMany<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Selector<span style="color: #002200;">&#41;</span>transform;</pre></td></tr></table></div>

<p>The unit test takes an array of string, projecting each element to an array via the <code>componentsSeparatedByString </code>method:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testSelectMany
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> data <span style="color: #002200;">=</span> @<span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;foo, bar&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;fubar&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> components <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>data selectMany<span style="color: #002200;">:^</span>id<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> <span style="color: #a61390;">string</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;, &quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    STAssertEquals<span style="color: #002200;">&#40;</span>components.count, 3U, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>components<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;foo&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>components<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bar&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>components<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;fubar&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>A more realistic example might take an array of orders, projecting each order to the order-items that it contains, with the result being all of the order-items over all orders … this could of course be followed by a ‘distinct’ query which would find all the distinct (i.e. unique) items ordered for a collection of orders.</p>
<p>The implementation involves a couple of nested for-in loops:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>selectMany<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Selector<span style="color: #002200;">&#41;</span>transform
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSMutableArray</span><span style="color: #002200;">*</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> item <span style="color: #a61390;">in</span> self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> child <span style="color: #a61390;">in</span> transform<span style="color: #002200;">&#40;</span>item<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>result addObject<span style="color: #002200;">:</span>child<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> result;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h3>Aggregate</h3>
<p>The next Linq method, aggregate, is an interesting one because it doesn’t return an array, instead it applies an accumulator function to the elements of an array, returning a single result. The signature is as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/** Applies an accumulator function over a sequence.
&nbsp;
 @param accumulator An accumulator function to be invoked on each element.
 @return The final accumulator value.
 */</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> aggregate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Accumulator<span style="color: #002200;">&#41;</span>accumulator;</pre></td></tr></table></div>

<p>The unit test uses this method to convert an array of strings into a CSV:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>testAggregate
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span> names <span style="color: #002200;">=</span> @<span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bill&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bob&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;brian&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">id</span> aggregate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>names aggregate<span style="color: #002200;">:^</span>id<span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> item, <span style="color: #a61390;">id</span> aggregate<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@, %@&quot;</span>, aggregate, item<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    STAssertEqualObjects<span style="color: #002200;">&#40;</span>aggregate, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bill, bob, brian&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Although you can use aggregate to do all sorts of things, such as find the maximum value for an array of integers.</p>
<p>The implementation is pretty simple, seeding the aggregate with the initial value and using the accumulator for subsequent items:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>aggregate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Accumulator<span style="color: #002200;">&#41;</span>accumulator
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">id</span> aggregate <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> item <span style="color: #a61390;">in</span> self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>aggregate <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            aggregate <span style="color: #002200;">=</span> item;
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
            aggregate <span style="color: #002200;">=</span> accumulator<span style="color: #002200;">&#40;</span>item, aggregate<span style="color: #002200;">&#41;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> aggregate;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<h2>A brief note on deferred execution</h2>
<p>In C# Linq methods do not act on arrays, instead they act upon the <code>IEnumerable<T></code> interface. This allows them to query anything that can be enumerated, which not only includes arrays, but can also include infinite sources of data (such as a stream of random numbers). The implementation of Linq relies on the ‘yield’ keyword, which results in the C# compiler creating a state machine to implement the <code>IEnumerable<T></code> interface.</p>
<p>The practical implication of all this very clever stuff is that Linq queries are not executed immediately. As an example, when you create a query as follows:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">var</span> query <span style="color: #008000;">=</span> PersonCollection<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">Age</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">.</span><span style="color: #0000FF;">OrderBy</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Nothing will actually happen until you start to enumerate the ‘query’ variable. In other words, you have to ‘pull’ data from the query. </p>
<p>This results in a feature which is often called ‘deferred execution’, where queries are executed on demand. This can yield tremendous performance benefits, allowing queries to terminate early.</p>
<p>Objective-C does not have ‘yield’ keyword, making it hard to implement Linq in such a way as to allow deferred execution. I did actually manage to create an implementation of a few query methods where each were presented as a state machine. Also, the Obj-C for-in iterator uses the <code>NSFastEnumeration</code>, which I was able to implement giving deferred execution and early termination. However, I decided to stick with the much simpler <code>NSArray </code>implementation here. If anyone is interested in the more complex version, give me a shout – I’d be happy to share.</p>
<h2>Conclusions</h2>
<p>Creating a Linq-style API for Objective-C has proven to be relatively simple (and fun!). I have provided implementations for some of the most common and useful Linq methods, however the .NET Linq APIs for querying collections have a great many more methods than the ones I have covered. </p>
<p>If you are interested, why not <a href="https://github.com/ColinEberhardt/LinqToObjectiveC">pop over to github</a>, fork and add a few more? I’ll probably add to this project myself over time.</p>
<p>Regards, Colin E.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2013/02/linq-to-objective-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CodeProject MVP 2013</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2013/01/codeproject-mvp-2013/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2013/01/codeproject-mvp-2013/#comments</comments>
		<pubDate>Mon, 07 Jan 2013 10:41:53 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=2349</guid>
		<description><![CDATA[TweetEarlier today I received an email informing me that I have been awarded a CodeProject MVP for the year 2013. I am very grateful to CodeProject for this award &#8211; it is a very popular website for developers, with around 10 million members, and thousands of authors. It is an honour to be among the [...]]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton2349" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F01%2Fcodeproject-mvp-2013%2F&amp;text=CodeProject%20MVP%202013&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F01%2Fcodeproject-mvp-2013%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.scottlogic.co.uk/blog/colin/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Earlier today I received an email informing me that I have been awarded a CodeProject MVP for the year 2013.  I am very grateful to CodeProject for this award &#8211; it is a very popular website for developers, with around 10 million members, and thousands of authors. It is an honour to be among the company of the <a href="http://www.codeproject.com/script/Awards/MVPWinners.aspx">~30 other MVPs</a>.</p>
<p><a href="http://www.codeproject.com/"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/04/codeproject.gif" alt="codeproject" width="225" height="72" class="aligncenter size-full wp-image-283" /></a></p>
<p>This year I have contributed five articles to Codeproject:</p>
<ul>
<li><a href="http://www.codeproject.com/Articles/365120/KnockoutJS-vs-Silverlight">KnockoutJS vs. Silverlight</a> &#8211; An article that helps people transition from Silverlight to Knockout and JavaScript.</li>
<li><a href="http://www.codeproject.com/Articles/342715/Plotting-Circular-Relationship-Graphs-with-Silverl">Plotting Circular Relationship Graphs with Silverlight</a> &#8211; An article that I wrote on my travels to Denmark, a bit of fun with data visualisation.</li>
<li><a href="http://www.codeproject.com/Articles/428088/A-Gesture-Driven-Windows-Phone-To-Do-List">A Gesture-Driven Windows Phone To-Do List</a> &#8211; which describes how to create a to-do list application which is controlled via multi-touch gestures. This article won the <em>&#8220;Best Mobile article of July 2012&#8243;</em> award.</li>
<li><a href="http://www.codeproject.com/Articles/445361/Property-Finder-a-Cross-Platform-HTML5-Mobile-App">Property Finder &#8211; a Cross-Platform HTML5 Mobile App</a> &#8211; which was an article about the use of HTML5 for cross-platform development, this was the &#8216;seed&#8217; for the <a href="http://www.propertycross.com">PropertyCross</a> project</li>
<li><a href="http://www.codeproject.com/Articles/473582/Clearer-A-Gesture-Driven-Windows-8-To-Do-Applicati">Clearer – A Gesture-Driven Windows 8 To-Do Application</a> &#8211; which was basically my attempt to win an Ultrabook by re-hashing my earlier Windows Phone article &#8230; which worked <img src='http://www.scottlogic.co.uk/blog/colin/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
</ul>
<p>That&#8217;s one more article than I contributed the previous year!</p>
<p>Over the past year my development interests have diversified, in 2011 I was mainly focused on WPF, Silverlight and Windows Phone. I now find myself spending just as much time on JavaScript and iOS &#8211; neither of which are really the core focus for CodeProject. I will probably be writing for <a href="http://www.raywenderlich.com/">Ray Wenderlich&#8217;s iOS</a> site just as much as CodeProject throughout 2013, however, I doubt I will ever give up on CodeProject. It has such a lively community, attracts some of the best technical authors, and provides them with a great environment to work within.</p>
<p>Regards, Colin E.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2013/01/codeproject-mvp-2013/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CodeProject Article on Xamarin Cross Platform Development</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2013/01/codeproject-article-on-xamarin-cross-platform-development/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2013/01/codeproject-article-on-xamarin-cross-platform-development/#comments</comments>
		<pubDate>Fri, 04 Jan 2013 09:54:30 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=2346</guid>
		<description><![CDATA[TweetYesterday I published a new article on CodePrioject: Property Finder – a Cross-Platform Xamarin MonoTouch Mobile App This article looks at how you can write a cross-platform mobile application with a shared C# code base using Xamarin MonoTouch. The application that is described in the article, a property finder, is exactly the same one that [...]]]></description>
				<content:encoded><![CDATA[<div id="tweetbutton2346" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F01%2Fcodeproject-article-on-xamarin-cross-platform-development%2F&amp;text=CodeProject%20Article%20on%20Xamarin%20Cross%20Platform%20Development&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.scottlogic.co.uk%2Fblog%2Fcolin%2F2013%2F01%2Fcodeproject-article-on-xamarin-cross-platform-development%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.scottlogic.co.uk/blog/colin/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div><p>Yesterday I published a new article on CodePrioject:</p>
<ul>
<li><a href="http://www.codeproject.com/Articles/520069/Property-Finder-a-Cross-Platform-Xamarin-MonoTouch">Property Finder – a Cross-Platform Xamarin MonoTouch Mobile App</a></li>
</ul>
<p>This article looks at how you can write a cross-platform mobile application with a shared C# code base using Xamarin MonoTouch. The application that is described in the article, a property finder, is exactly the same one that <a href="http://www.codeproject.com/Articles/445361/Property-Finder-a-Cross-Platform-HTML5-Mobile-App">I wrote using HTML5</a> a few months earlier. This most recent article provides an interesting comparison of the two different techniques.</p>
<p>I actually wrote most of this article about two months ago, it was at this point I decided to embark on <a href="http://www.scottlogic.co.uk/blog/colin/2012/12/introducing-propertycross-helping-you-select-a-cross-platform-mobile-framework/" title="Introducing PropertyCross – Helping you select a cross-platform mobile framework">PropertyCross</a>, which provides a comparison of a wide range of cross-platform frameworks.</p>
<p>After finishing PropertyCross I decided that the original article was still worth publishing, it provides a lot of technical detail on how to code share with Xamarin specifically. </p>
<p>So, why not pop over to CodeProject and check it out?</p>
<p><a href="http://www.codeproject.com/Articles/520069/Property-Finder-a-Cross-Platform-Xamarin-MonoTouch"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/04/codeproject.gif" alt="codeproject" width="225" height="72" class="aligncenter size-full wp-image-283" /></a></p>
<p>Regards, Colin E.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2013/01/codeproject-article-on-xamarin-cross-platform-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
