<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Dimzzy</title>
	
	<link>http://www.dimzzy.com/blog</link>
	<description>Mac OS X and iOS Development Services</description>
	<lastBuildDate>Fri, 13 Jan 2012 16:25:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/dimzzy" /><feedburner:info uri="dimzzy" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Separator cells for UITableView</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/EfGN4AqsTBU/</link>
		<comments>http://www.dimzzy.com/blog/2012/01/separator-cells-for-uitableview/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 16:25:24 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=318</guid>
		<description><![CDATA[By default UITableView manages cell separator views by itself. You only can set separatorColor and separatorStyle properties for the table, which actually is quite limiting because style could be 'no separators', solid line or etched line. If you want to use dotted line or specify some offsets then you are out of luck. What's interesting [...]]]></description>
			<content:encoded><![CDATA[<p>By default UITableView manages cell separator views by itself. You only can set <code>separatorColor</code> and <code>separatorStyle</code> properties for the table, which actually is quite limiting because style could be 'no separators', solid line or etched line. If you want to use dotted line or specify some offsets then you are out of luck.</p>
<p>What's interesting is that cells actually have references to separator views. Just open UITableViewCell.h file and look at cell's ivars; it has</p>
<pre class="prettyprint">
    UIView *_separatorView;
    UIView *_topSeparatorView;
</pre>
<p>which are clearly bottom and top separator views for the cell. I don't know why Apple does not expose them or does not allow to customize them in some way&mdash;it could have saved so much time…</p>
<p>So what could be done to alleviate this? How could we provide our own custom separators? The easiest solution (and I guess that's what most devs do) is to set <code>separatorStyle</code> to 'no separators' and add custom separator views to the content view of every cell. It works, but not that well. First you have to hide top separator view for each cell except the one at the bottom and what's most important these views are resized when table is being edited.</p>
<p>Another solution which I provide here is to add separators as cells. I've written a special table provider that wraps your provider (data source + delegate) and inserts these cells. Below is an API of this provider:</p>
<pre class="prettyprint">
enum {
	BACellSeparatorPositionNone = 0,
	BACellSeparatorPositionTop = 1 &lt;&lt; 0,
	BACellSeparatorPositionBottom = 1 &lt;&lt; 1
};

typedef NSUInteger BACellSeparatorPositions;

@protocol BASeparatedTableProviderDelegate
    &lt;NSObject, UITableViewDataSource, UITableViewDelegate&gt;

- (BACellSeparatorPositions)tableView:(UITableView *)tableView
    separatorPositionsForRow:(NSIndexPath *)indexPath;

- (UITableViewCell *)tableView:(UITableView *)tableView
    topSeparatorCellForRowAtIndexPath:(NSIndexPath *)indexPath;

- (UITableViewCell *)tableView:(UITableView *)tableView
    bottomSeparatorCellForRowAtIndexPath:(NSIndexPath *)indexPath;

- (CGFloat)tableView:(UITableView *)tableView
    heightForTopSeparatorRowAtIndexPath:(NSIndexPath *)indexPath;

- (CGFloat)tableView:(UITableView *)tableView
    heightForBottomSeparatorRowAtIndexPath:(NSIndexPath *)indexPath;

@end

@interface BASeparatedTableProvider : NSObject
    &lt;UITableViewDataSource, UITableViewDelegate&gt;

@property(nonatomic, assign) id&lt;BASeparatedTableProviderDelegate&gt; delegate;

- (NSIndexPath *)separatedIndexPathForIndexPath:(NSIndexPath *)indexPath;
- (NSArray *)separatedIndexPathsForIndexPaths:(NSArray *)indexPaths;

@end
</pre>
<p>So all that you have to do is to implement five methods that provide separator positions for the cell, their views and heights. In most cases top and bottom separators are the same so effectively you have to add code just to create the custom separator cell.</p>
<p>Class BASeparatedTableProvider is part of the <a href="http://baseappkit.com/">BaseAppKit framework</a> but does not depend much on other classes so you can just copy it into your project. Not all methods are implemented yet; you should be able to show table contents and edit it but some delegate methods just won't be called.</p>
<p>I was not sure about performance of this approach and its feasibility but so far it works well. I'm using this code in production and there seems to be no issues with it.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/EfGN4AqsTBU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="318 http://www.dimzzy.com/blog/?p=318">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2012/01/separator-cells-for-uitableview/</feedburner:origLink></item>
		<item>
		<title>Interactive story app for kids: Mices New Year</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/EY99q80BuC0/</link>
		<comments>http://www.dimzzy.com/blog/2011/12/interactive-story-app-mices-new-year/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 10:54:41 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=302</guid>
		<description><![CDATA[My first interactive book for kids is in App Store! Right now it is possible to read the book by turning pages and touch the text to listen to it. All pages have palette icon which brings a painter module where you could color the page's image by finger. I'm very excited about the project [...]]]></description>
			<content:encoded><![CDATA[<p>My first interactive book for kids is in App Store! Right now it is possible to read the book by turning pages and touch the text to listen to it. All pages have palette icon which brings a painter module where you could color the page's image by finger. I'm very excited about the project and already working on more stuff )))</p>
<table border=0>
<tr>
<td><a href="/blog/wp-content/uploads/2011/12/MicesNewYear1.jpg" rel="lightbox-micesnewyear"><br />
					<img src="/blog/wp-content/uploads/2011/12/MicesNewYear1t.png" width="160" height="120"/><br />
				</a></td>
<td><a href="/blog/wp-content/uploads/2011/12/MicesNewYear2.jpg" rel="lightbox-micesnewyear"><br />
					<img src="/blog/wp-content/uploads/2011/12/MicesNewYear2t.png" width="160" height="120"/><br />
				</a></td>
<td><a href="/blog/wp-content/uploads/2011/12/MicesNewYear3.jpg" rel="lightbox-micesnewyear"><br />
					<img src="/blog/wp-content/uploads/2011/12/MicesNewYear3t.png" width="160" height="120"/><br />
				</a></td>
</tr>
</table>
<p>I have two daughters (2 and 4 years old) and actually many of the UI decisions were made by watching them using the app. For example the biggest issue with many apps for kids is that they have on-screen controls to change preferences or share something and children often get stuck with this.  I made a decision to remove any such buttons; you have to make a pinch gesture to show bars with navigation and other controls.</p>
<h3><a href="http://itunes.apple.com/us/app//id490763711?mt=8">[ DOWNLOAD APP ]</a></h3>
<p>I also have some promo codes to share:</p>
<ul>
<li>WF9KRMJFPENK</li>
<li>HMF63K66PJLY</li>
<li>F34L4K9H79RK</li>
<li>JMLY7YJ4MTLP</li>
<li>KXJR33RFWAY9</li>
</ul>
<p>Here is also <a href="http://ipadis.ru/games/other/897-myshinyy-novyy-god-kniga-s-drugogo-vzglyada.html">the first review</a> of the app.<br />
<br/></p>
<h4>P.S.</h4>
<p>If you are an artist and interested in publishing your drawings or story for iPad please <a href="mailto:dimzzy@gmail.com">drop me a letter</a>. I'm looking for more content for the project.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/EY99q80BuC0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="302 http://www.dimzzy.com/blog/?p=302">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/12/interactive-story-app-mices-new-year/</feedburner:origLink></item>
		<item>
		<title>AMC: NSCoding alternative</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/JBYcPlYK0KQ/</link>
		<comments>http://www.dimzzy.com/blog/2011/12/amc-nscoding-alternative/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 09:53:32 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=300</guid>
		<description><![CDATA[I appreciate NSCoding protocol and the overall design of serialization of NSObjects but sometimes I wish it would be simpler. If your model is made of plain objects with simple properties why should you write a lot of code to serialize and deserialize them? Objective-C allows to introspect objects and figure out which setters and [...]]]></description>
			<content:encoded><![CDATA[<p>I appreciate NSCoding protocol and the overall design of serialization of NSObjects but sometimes I wish it would be simpler. If your model is made of plain objects with simple properties why should you write a lot of code to serialize and deserialize them? Objective-C allows to introspect objects and figure out which setters and getters to use to do all the work.</p>
<p>It looks like <a href="https://github.com/psineur/NSObject-AutomagicCoding">Automagic Coding</a> is just doing so. I've just stalked the code and have not used it yet but I guess I'll give it a try on the next occasion. So far it seems pretty powerful and I guess it will save me some routine coding.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/JBYcPlYK0KQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="300 http://www.dimzzy.com/blog/?p=300">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/12/amc-nscoding-alternative/</feedburner:origLink></item>
		<item>
		<title>App Store Affiliate Program</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/PPjFboKnv5k/</link>
		<comments>http://www.dimzzy.com/blog/2011/11/app-store-affiliate-program/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 22:35:32 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=298</guid>
		<description><![CDATA[Watching this Mixergy podcast I've realized that I completely forgot about this affiliate scheme for iTunes links! Turns out there are people that use it and make a cool bonus for themselves from the program...]]></description>
			<content:encoded><![CDATA[<p>Watching <a href="http://mixergy.com/modha-sharma-fiplab-interview/">this Mixergy podcast</a> I've realized that I completely forgot about this affiliate scheme for iTunes links! Turns out there are people that use it and make a cool bonus for themselves from the program...</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/PPjFboKnv5k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="298 http://www.dimzzy.com/blog/?p=298">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/11/app-store-affiliate-program/</feedburner:origLink></item>
		<item>
		<title>BASequenceControl to complement UISegmentedControl</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/C0DIZ-A53OY/</link>
		<comments>http://www.dimzzy.com/blog/2011/11/basequencecontrol-to-complement-uisegmentedcontrol/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 22:23:14 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=295</guid>
		<description><![CDATA[I recently needed something like UISegmentedControl but with &#34;direction&#34; theme. As a result BaseAppKit got a new control&#8212;BASequenceControl. I've tried to mimic API of the UISegmentedControl and basically it's the same except that now I support only strings in segments. It's customizable; you can provide these two images to completely change the theme of the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed something like UISegmentedControl but with &quot;direction&quot; theme. As a result <a href="https://github.com/dimzzy/BaseAppKit">BaseAppKit</a> got a new control&mdash;BASequenceControl. I've tried to mimic API of the UISegmentedControl and basically it's the same except that now I support only strings in segments.</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.dimzzy.com/blog/wp-content/uploads/2011/11/BASequenceControl.png" alt="BASequenceControl" border="0" width="320" height="480" /></p>
<p>It's customizable; you can provide these two images to completely change the theme of the control:</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.dimzzy.com/blog/wp-content/uploads/2011/11/ba-sequence-item-passive.png" alt="ba-sequence-item-passive.png" border="0" width="44" height="44" /><br />
<br/><br />
<img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.dimzzy.com/blog/wp-content/uploads/2011/11/ba-sequence-item-active.png" alt="ba-sequence-item-active.png" border="0" width="44" height="44" /></p>
<p>As selected segment got changed the BASequenceControl sends UIControlEventValueChanged event just like the UISegmentedControl.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/C0DIZ-A53OY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="295 http://www.dimzzy.com/blog/?p=295">4</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/11/basequencecontrol-to-complement-uisegmentedcontrol/</feedburner:origLink></item>
		<item>
		<title>Bezel for BALabel</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/qDAXVcMtsXU/</link>
		<comments>http://www.dimzzy.com/blog/2011/11/bezel-for-balabel/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 22:09:36 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=288</guid>
		<description><![CDATA[BALabel just got an update and now it can draw a bezel below the text. It could be a solid rounded rectangle or just it's frame. You can set line width and color of the bezel.]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/dimzzy/BaseAppKit">BALabel</a> just got an update and now it can draw a bezel below the text. It could be a solid rounded rectangle or just it's frame. You can set line width and color of the bezel.</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.dimzzy.com/blog/wp-content/uploads/2011/11/BALabelBezel.png" alt="BALabel with bezel" border="0" width="320" height="480" /></p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/qDAXVcMtsXU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="288 http://www.dimzzy.com/blog/?p=288">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/11/bezel-for-balabel/</feedburner:origLink></item>
		<item>
		<title>How to send tweets on iOS 5 and stay compatible with older versions</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/K6yMU2RS6a4/</link>
		<comments>http://www.dimzzy.com/blog/2011/11/how-to-send-tweets-on-ios-5-and-stay-compatible-with-older-versions/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 23:15:36 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=285</guid>
		<description><![CDATA[With the new Twitter framework it's much easier to integrate apps with this service, except when you have to run on older iOS versions. If integration is not imperative and you can skip Twitter feature for older clients you still have to write your code in a way that the app does not crash on [...]]]></description>
			<content:encoded><![CDATA[<p>With the new Twitter framework it's much easier to integrate apps with this service, except when you have to run on older iOS versions. If integration is not imperative and you can skip Twitter feature for older clients you still have to write your code in a way that the app does not crash on iOS 4 or earlier.</p>
<p>The first step is to add Twitter framework to the project. You do it as usual but change 'Required' setting to 'Optional' so if the framework is not available the app will be able to start anyway.</p>
<p>Next in your view controller import &lt;Twitter/Twitter.h&gt; and add the following method:</p>
<pre class="prettyprint">
- (IBAction)tweet:(NSString *)text image:(UIImage *)image {
  if ([TWTweetComposeViewController canSendTweet]) {
    TWTweetComposeViewController *controller =
      [[[TWTweetComposeViewController alloc] init] autorelease];
    [controller setInitialText:text];
    if (image) {
      [controller addImage:image];
    }
    [self presentModalViewController:controller animated:YES];
  }
}
</pre>
<p>It will work on iOS 5 but won't on earlier versions and the reason is that we try to load TWTweetComposeViewController class and fail to do so. What we should do is to remove the direct reference to it and load it in a 'safe' way:</p>
<pre class="prettyprint">
- (IBAction)tweet:(NSString *)text image:(UIImage *)image {
  Class cclass = NSClassFromString(@"TWTweetComposeViewController");
  if (cclass &#038;& [cclass canSendTweet]) {
    id controller = [[[cclass alloc] init] autorelease];
    [controller setInitialText:text];
    if (image) {
      [controller addImage:image];
    }
    [self presentModalViewController:controller animated:YES];
  }
}
</pre>
<p>This second implementation will work on any iOS version. The same approach could be used in all other cases when you have to make use of some new iOS feature and stay compatible with previous releases.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/K6yMU2RS6a4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="285 http://www.dimzzy.com/blog/?p=285">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/11/how-to-send-tweets-on-ios-5-and-stay-compatible-with-older-versions/</feedburner:origLink></item>
		<item>
		<title>Disappointed with Adfonic</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/F1YF6GNCnz0/</link>
		<comments>http://www.dimzzy.com/blog/2011/10/disappointed-with-adfonic/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 19:50:35 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=281</guid>
		<description><![CDATA[I've tried to use Adfonic in Deviations app and see how it compares to AdMob. I gave it a part of the screen next to the AdMob so they use the same 320x50 size. Over the last several days Adfonic reports 2306 impressions and 0 clicks. I guess it's time to say goodbye to Adfonic. [...]]]></description>
			<content:encoded><![CDATA[<p>I've tried to use Adfonic in Deviations app and see how it compares to AdMob. I gave it a part of the screen next to the AdMob so they use the same 320x50 size. Over the last several days Adfonic reports 2306 impressions and 0 clicks. I guess it's time to say goodbye to Adfonic.</p>
<p>I'm also playing with <a href="http://www.myinstallwall.com/">InstallWall</a> and <a href="http://www.flurry.com/product/appcircle/index.html">AppCircle</a>; so far I can't say that they were a great success but let's see how it goes.</p>
<p>If you know some other services to promote or monetize the app I'd be happy to try...</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/F1YF6GNCnz0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="281 http://www.dimzzy.com/blog/?p=281">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/10/disappointed-with-adfonic/</feedburner:origLink></item>
		<item>
		<title>Evolution of Objective-C properties</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/2Oo17S3hQPk/</link>
		<comments>http://www.dimzzy.com/blog/2011/10/evolution-of-objective-c-properties/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 16:34:31 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=279</guid>
		<description><![CDATA[I'm writing code in Objective-C for just several years but it's quite amazing to see how the language, compiler and its primary IDE, Xcode, evolve. And the language in particular. Initially it was a thin addition to the C language to provide notion of objects and it remained so for a long time, but now [...]]]></description>
			<content:encoded><![CDATA[<p>I'm writing code in Objective-C for just several years but it's quite amazing to see how the language, compiler and its primary IDE, Xcode, evolve. And the language in particular. Initially it was a thin addition to the C language to provide notion of objects and it remained so for a long time, but now every year we see new features coming to the language. Below I have two classes, DataBagX and DataBagY to illustrate the changes.</p>
<p>The first class, DataBagX, is the class that I would have written in 2008. Note that there is no special syntax for properties: you have to define instance variables, getters and setters. What you call property is a pure naming convention; you have to analyze public methods to figure out that there are two properties: prop1 and prop2.</p>
<p>What many people really hate about this approach to class definition is that instance variables are exposed in public interface file. It's not just wrong logically because you reveal implementation details but you also have to add forward class definitions for contained objects or include their header files, which are completely irrelevant to the clients of the class being defined.</p>
<p>The positive side of such definition is simplicity&mdash;you don't have to know much of the language to understand what's going on. Here are instance variables, and there are methods that work with them.</p>
<h4>DataBagX.h</h4>
<pre class="prettyprint">
@interface DataBagX : NSObject {
@private
  int _prop1;
  double _prop2m;
}

- (int)prop1;
- (void)setProp1:(int)prop1;
- (double)prop2;
- (void)setProp2:(double)prop2;

@end
</pre>
<h4>DataBagX.m</h4>
<pre class="prettyprint">
#import "DataBagX.h"

@implementation DataBagX

- (int)prop1 {
  return _prop1;
}

- (void)setProp1:(int)prop1 {
  _prop1 = prop1;
}

- (double)prop2 {
  return _prop2m / 2;
}

- (void)setProp2:(double)prop2 {
  _prop2m = prop2 * 2;
}

@end
</pre>
<p>Fast forward to 2011: here is the same class rewritten using the new language features. The most noticeable thing is that interface contains just necessary information in a very compact form. We have two properties? So here they are: just a keyword of property definition, type and name. All the implementation details go into implementation file.</p>
<p>And implementation is quite spectacular too: for ordinary properties it's just enough to synthesize it in one line. Also note how definition of instance variables is possible in implementation file, right where it should be from the beginning.</p>
<h4>DataBagY.h</h4>
<pre class="prettyprint">
#import <Foundation/Foundation.h>

@interface DataBagY : NSObject

@property int prop1;
@property double prop2;

@end
</pre>
<h4>DataBagY.m</h4>
<pre class="prettyprint">
#import "DataBagY.h"

@implementation DataBagY {
@private
  double _prop2m;
}

@synthesize prop1 = _prop1;

- (double)prop2 {
  return _prop2m / 2;
}

- (void)setProp2:(double)prop2 {
  _prop2m = prop2 * 2;
}

@end
</pre>
<p>These are just several improvements that you will encounter most frequently but change class definitions quite dramatically. I'd recommend you to watch <a href="http://developer.apple.com/videos/wwdc/2011/">WWDC 2011 videos</a> to learn more about the Objective-C and "Session 322 - Objective-C Advancements in Depth" in particular.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/2Oo17S3hQPk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="279 http://www.dimzzy.com/blog/?p=279">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/10/evolution-of-objective-c-properties/</feedburner:origLink></item>
		<item>
		<title>Proper deselection in UITableView</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/cdrhMsaKhxk/</link>
		<comments>http://www.dimzzy.com/blog/2011/10/proper-deselection-in-uitableview/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 19:27:07 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=277</guid>
		<description><![CDATA[It may not be obvious but the proper way to deselect a cell is this: - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES]; } And of course not in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath. And the reason is that when you return from the details page you see how the cell is being deselected, [...]]]></description>
			<content:encoded><![CDATA[<p>It may not be obvious but the proper way to deselect a cell is this:</p>
<pre class="prettyprint">
- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow]
                                animated:YES];
}
</pre>
<p>And of course not in <code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath</code>. And the reason is that when you return from the details page you see how the cell is being deselected, which hints you about your previous choice and just looks nice.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/cdrhMsaKhxk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="277 http://www.dimzzy.com/blog/?p=277">3</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/10/proper-deselection-in-uitableview/</feedburner:origLink></item>
		<item>
		<title>FacebookKit</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/aDMgfb7GQzc/</link>
		<comments>http://www.dimzzy.com/blog/2011/10/facebookkit/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 21:31:00 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=275</guid>
		<description><![CDATA[I've got tired of copying only necessary classes from the official Facebook SDK and decided to make a fork of it. Here is what it gives you: Only necessary classes, no sample code. You could do git submodule add https://github.com/dimzzy/FacebookKit.git to add it to your projects. Dynamic selection of JSON parser. It uses NSJSONSerialization on [...]]]></description>
			<content:encoded><![CDATA[<p>I've got tired of copying only necessary classes from the <a href="https://github.com/facebook/facebook-ios-sdk">official Facebook SDK</a> and decided to make a fork of it. Here is what it gives you:</p>
<ul>
<li>Only necessary classes, no sample code. You could do <code>git submodule add https://github.com/dimzzy/FacebookKit.git</code> to add it to your projects.</li>
<li>Dynamic selection of JSON parser. It uses NSJSONSerialization on iOS 5 and on older versions it tries to load JSONKit.</li>
<li>Fixed bug where proper delegate method was not called when user cancels post dialog.</li>
</ul>
<p>Here it is on GitHub: <a href="https://github.com/dimzzy/FacebookKit">FacebookKit</a></p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/aDMgfb7GQzc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="275 http://www.dimzzy.com/blog/?p=275">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/10/facebookkit/</feedburner:origLink></item>
		<item>
		<title>Dynamic selection of JSON parser</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/HbGtcJ-bUUA/</link>
		<comments>http://www.dimzzy.com/blog/2011/10/dynamic-selection-of-json-parser/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 20:28:31 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=273</guid>
		<description><![CDATA[At last iOS got built-in JSON parser! Check Xcode help for NSJSONSerialization to see the new API. Unfortunately we still have to support older iOS versions without JSON parser and the best library for this so far is JSONKit. I guess it will be phased out eventually, but how to make this transition smooth? Below [...]]]></description>
			<content:encoded><![CDATA[<p>At last iOS got built-in JSON parser! Check Xcode help for NSJSONSerialization to see the new API. Unfortunately we still have to support older iOS versions without JSON parser and the best library for this so far is <a href="https://github.com/johnezang/JSONKit">JSONKit</a>. I guess it will be phased out eventually, but how to make this transition smooth? Below is the code that I'm going to use to parse JSON code in all current projects:</p>
<pre class="prettyprint">
id result = nil;
if ([NSJSONSerialization self]) {
    NSError *error = nil;
    result = [NSJSONSerialization JSONObjectWithData:data options:0 error:&#038;error];
    if (error) {
        NSLog(@"%@", error);
    }
} else if ([data respondsToSelector:NSSelectorFromString(@"objectFromJSONData")]) {
    result = [data performSelector:NSSelectorFromString(@"objectFromJSONData")];
} else {
    NSLog(@"JSON parser is not available");
}
</pre>
<p>This code should be compiled with iOS 5 SDK and it will work on earlier iOS versions. It tries to parse data using the new JSON parser and if it's not available it falls back to JSONKit (or actually any other JSON parser which adds <code>-(id)objectFromJSONData</code> method to NSData). I will continue to include JSONKit in all my projects that need a JSON parser but now there is no direct dependency and when iOS 5 becomes the lowest supported version JSONKit could be just safely removed.</p>
<p>Don't get me wrong though; actually it is an amazing piece of software, it is fast, reliable and works great but it's still one more dependency and third party library to manage. So I'm using this post also to thank the <a href="https://github.com/johnezang">author of JSONKit</a> and wish him all the best!</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/HbGtcJ-bUUA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="273 http://www.dimzzy.com/blog/?p=273">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/10/dynamic-selection-of-json-parser/</feedburner:origLink></item>
		<item>
		<title>BALabel: text insets and vertical alignment</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/9fAuAMI_x0w/</link>
		<comments>http://www.dimzzy.com/blog/2011/10/balabel-text-insets-and-vertical-alignment/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 12:46:06 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=269</guid>
		<description><![CDATA[Actually I was planning to make this one for a long time so here it goes: subclass of UILabel with better positioning options. Right now there are just two additional features and an utility method to update label size. @interface BALabel : UILabel { @private UIEdgeInsets _textInsets; BAVerticalAlignment _verticalAlignment; } @property(nonatomic, assign) UIEdgeInsets textInsets; @property(nonatomic, [...]]]></description>
			<content:encoded><![CDATA[<p>Actually I was planning to make this one for a long time so here it goes: subclass of UILabel with better positioning options. Right now there are just two additional features and an utility method to update label size.</p>
<pre class="prettyprint">
@interface BALabel : UILabel {
@private
    UIEdgeInsets _textInsets;
    BAVerticalAlignment _verticalAlignment;
}

@property(nonatomic, assign) UIEdgeInsets textInsets;
@property(nonatomic, assign) BAVerticalAlignment verticalAlignment;

- (void)sizeToFitInWidth;
- (void)sizeToFitInWidthMaxHeight:(CGFloat)maxHeight;

@end
</pre>
<h3>Text Insets</h3>
<p>It may not be obvious why you could need them but if you'd try to use label as a table section header view you will understand ))). So BALabel has <code>textInsets</code> property which is UIEdgeInsets and it offsets text within label bounds and also is used in label size calculation.</p>
<h3>Vertical Alignment</h3>
<p>Right now it's possible to align text within the UILabel to the left or to the right or have it centered. Somehow vertical alignment is missing but BALabel allows to stick text to the top, to the bottom or have it centered (which is the default). You probably will need it for multiline labels; if text could span several lines you make text bounds large enough to fit these lines, but if in runtime you have just one short line then it will be centered, which may not look great. You could calculate new height which fits just the available lines but it's much easier to tell label to align text to the top.</p>
<h3>sizeToFitInWidth[MaxHeight:]</h3>
<p>These are two methods to help you layout labels that are stacked on top of each other where some of them could have several lines of text. Typically you would like them to keep their width and maintain certain spacing. So you call this method(s) for all labels and move them to keep the spacing.</p>
<p><br/><br />
<img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.dimzzy.com/blog/wp-content/uploads/2011/10/balabel.png" alt="BALabel Demo" border="0" width="320" height="480" /></p>
<p>Here is a demo page that shows these features. BALabel is part of the <a href="http://baseappkit.com/">BaseAppKit</a> library.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/9fAuAMI_x0w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="269 http://www.dimzzy.com/blog/?p=269">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/10/balabel-text-insets-and-vertical-alignment/</feedburner:origLink></item>
		<item>
		<title>AdMob House Ads</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/jMjldXAJyus/</link>
		<comments>http://www.dimzzy.com/blog/2011/10/admob-house-ads/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 11:46:46 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=266</guid>
		<description><![CDATA[I had no problems with AdMob until I saw this: So I'm running a campaign to cross-promote Deviations in other apps, but why, why on Earth they show my ad within my own app??? Now I did setup text filters and app filters for my app, but this all looks crazy for me...]]></description>
			<content:encoded><![CDATA[<p>I had no problems with AdMob until I saw this:</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://www.dimzzy.com/blog/wp-content/uploads/2011/10/deviations_house_ad.png" alt="Deviations House Ads" border="0" width="400" height="600" /></p>
<p>So I'm running a campaign to cross-promote Deviations in other apps, but why, why on Earth they show my ad within my own app??? Now I did setup text filters and app filters for my app, but this all looks crazy for me...</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/jMjldXAJyus" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="266 http://www.dimzzy.com/blog/?p=266">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/10/admob-house-ads/</feedburner:origLink></item>
		<item>
		<title>Fixing invalid JSON before parsing</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/yke9rVTStNY/</link>
		<comments>http://www.dimzzy.com/blog/2011/09/fixing-invalid-json-before-parsing/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 10:57:32 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=259</guid>
		<description><![CDATA[It turns out that all JSON parsers for iOS are quite strict and fail to parse JSON that is parsed by web browsers. For example this piece of code is properly recognized by web browser but can't be parsed by any iOS parser (I've tested JSONKit, TouchJSON and SBJSON): { image: "http://img.skitch.com/20100423-jepjp1x576hxfii15ixfxyuacr.png", title: "Don't panic", [...]]]></description>
			<content:encoded><![CDATA[<p>It turns out that all JSON parsers for iOS are quite strict and fail to parse JSON that is parsed by web browsers. For example this piece of code is properly recognized by web browser but can't be parsed by any iOS parser (I've tested JSONKit, TouchJSON and SBJSON):</p>
<pre class="prettyprint">
{
image: "http://img.skitch.com/20100423-jepjp1x576hxfii15ixfxyuacr.png",
title: "Don't panic",
url: "http://www.google.com"
}
</pre>
<p>But there is an easy fix for this, just add double quotes around names and we have a valid JSON. I wrote the following function that you could call before feeding the string to any parser and so far it seems to be working well for me:</p>
<pre class="prettyprint">
+ (NSString *)fixJSON:(NSString *)s {
  NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:
                                                     @"[{,]\\s*(\\w+)\\s*:"
                                      options:0
                                        error:NULL];
  NSMutableString *b = [NSMutableString stringWithCapacity:([s length] * 1.1)];
  __block NSUInteger offset = 0;
  [regexp enumerateMatchesInString:s
               options:0
                 range:NSMakeRange(0, [s length])
              usingBlock:^(NSTextCheckingResult *result,
                           NSMatchingFlags flags, BOOL *stop)
   {
     NSRange r = [result rangeAtIndex:1];
     [b appendString:[s substringWithRange:NSMakeRange(offset,
                                       r.location - offset)]];
     [b appendString:@"\""];
     [b appendString:[s substringWithRange:r]];
     [b appendString:@"\""];
     offset = r.location + r.length;
  }];
  [b appendString:[s substringWithRange:NSMakeRange(offset,
                                    [s length] - offset)]];
  return b;
}
</pre>
<p>If you see any way to improve it or I've missed something please let me know.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/yke9rVTStNY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="259 http://www.dimzzy.com/blog/?p=259">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/09/fixing-invalid-json-before-parsing/</feedburner:origLink></item>
		<item>
		<title>Featured library: BlocksKit</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/e1MNXOxZlgY/</link>
		<comments>http://www.dimzzy.com/blog/2011/09/featured-library-blockskit/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 14:27:48 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=257</guid>
		<description><![CDATA[I clearly remember that the first time I've heard about Objective-C blocks I was skeptical: how could you add something simple and useful to the language that exists for so long? It's hard to add a new feature to the language properly; Java generics for example is still a point of controversy. But the blocks [...]]]></description>
			<content:encoded><![CDATA[<p>I clearly remember that the first time I've heard about Objective-C blocks I was skeptical: how could you add something simple and useful to the language that exists for so long? It's hard to add a new feature to the language properly; Java generics for example is still a point of controversy. But the blocks are really done well. It's a language feature that you dearly miss when forced not to use.</p>
<p>The first thing that you start to do when you 'get' the blocks is that you use them everywhere. It not only becomes a part of your code but you want to add them to the existing code to follow your new style. So here is the library of such additions: <a href="https://github.com/zwaldowski/BlocksKit">https://github.com/zwaldowski/BlocksKit</a></p>
<p>At the moment of this writing the library features:</p>
<ul>
<li>Performing blocks on an <code>NSObject</code>.</li>
<li>Key-value observation (<code>&lt;NSKeyValueObserving&gt;</code>) using a block handler</li>
<li>Associated objects using an Obj-C API.  (Not directly block-related.)</li>
<li>
<code>NSArray</code>, <code>NSSet</code>, and <code>NSDictionary</code> filter utilities</li>
<li>BKMacros, for more quickly typing out the above.</li>
<li>
<code>NSInvocation</code> creation using blocks</li>
<li>
<code>NSTimer</code> block execution</li>
<li>
<code>UIAlertView</code>, <code>UIActionSheet</code> with block callbacks</li>
<li>Block initializers for <code>UIControl</code> and <code>UIBarButtonItem</code>
</li>
<li>Initializer for <code>UIGestureRecognizer</code>
</li>
<li>On-touch utilities for <code>UIView</code>.</li>
<li>both delegation and block callbacks on <code>NSURLConnection</code>
</li>
</ul>
<p>The list of contributors is also quite impressive:</p>
<ul>
<li>
<a href="https://github.com/mikeash">Michael Ash</a>.</li>
<li>
<a href="https://github.com/jivadevoe">Jiva DeVoe</a>.</li>
<li>
<a href="https://github.com/evsukov89">Igor Evsukov</a>.</li>
<li>
<a href="https://github.com/coreyfloyd">Corey Floyd</a>.</li>
<li>
<a href="http://plausiblelabs.com">Landon Fuller, Plausible Labs</a>.</li>
<li>
<a href="https://github.com/mirkok">Mirko Kiefer</a>.</li>
<li>
<a href="https://github.com/robin">Robin Lu</a>.</li>
<li>
<a href="https://github.com/jakemarsh">Jake Marsh</a>.</li>
<li>
<a href="https://github.com/andymatuschak">Andy Matuschak</a>.</li>
<li>
<a href="https://github.com/nesterow">Aleks Nesterow</a>.</li>
<li>
<a href="https://github.com/kevinoneill">Kevin O'Neill</a>.</li>
<li>
<a href="https://github.com/rentzch">Jonathan Rentzch</a>.</li>
<li>
<a href="https://github.com/steipete">Peter Steinberger</a>.</li>
<li>
<a href="https://github.com/jonsterling">Jon Sterling</a>.</li>
<li>
<a href="https://github.com/MSch">Martin Schürrer</a>.</li>
<li>
<a href="https://github.com/zwaldowski">Zach Waldowski</a>.</li>
<li>
<a href="https://github.com/schwa">Jonathan Wight</a>.</li>
</ul>
<p>So even if you are not ready to dive into full-scale blocks usage I would still recommend to have a look at this code for educational purposes.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/e1MNXOxZlgY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="257 http://www.dimzzy.com/blog/?p=257">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/09/featured-library-blockskit/</feedburner:origLink></item>
		<item>
		<title>AudioStreamer with power metering and icy tags</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/mRvqP0TaYwE/</link>
		<comments>http://www.dimzzy.com/blog/2011/09/audiostreamer-with-power-metering-and-icy-tags/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 11:59:29 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=255</guid>
		<description><![CDATA[I've been using AudioStreamer by Matt Gallagher for a while and it works perfectly for playing internet radio. On the other hand I was missing two features: power metering and metadata available in the stream. So the power metering stuff was easy: you just enable power metering and ask audio queue for kAudioQueueProperty_CurrentLevelMeter property and [...]]]></description>
			<content:encoded><![CDATA[<p>I've been using <a href="https://github.com/mattgallagher/AudioStreamer">AudioStreamer by Matt Gallagher</a> for a while and it works perfectly for playing internet radio. On the other hand I was missing two features: power metering and metadata available in the stream. So the power metering stuff was easy: you just enable power metering and ask audio queue for kAudioQueueProperty_CurrentLevelMeter property and then extract average and peak power levels. I've added them to the AudioStreamer interface like this:</p>
<pre class="prettyprint">
@property (readonly) double averagePower;
@property (readonly) double peakPower;
</pre>
<p>If you are curious what to do with these values check out <a href="http://developer.apple.com/library/ios/#samplecode/avTouch/Introduction/Intro.html">avTouch sample project</a> which contains nice views to show power level.</p>
<p>Metadata was a bit harder task. It turns out that I had Shoutcast stream with icy tags for song title. There is a very detailed <a href="http://jicyshout.sourceforge.net/oreilly-article/java-streaming-mp3-pt2/java-streaming-mp3-pt2.html">article that describes metadata</a> in audio streams and I followed it to upgrade AudioStreamer to extract song info.</p>
<p>The first step is actually to ask for the metadata: you send 'Icy-Metadata:1' in HTTP request and get 'icy-metaint:8192' in HTTP response header. The value is the size of audio blocks between which you get the metadata. Metadata itself is a size byte followed by string that looks like this:</p>
<pre>
StreamTitle='Artist Name - Song Name';
</pre>
<p>The second step is to extract the string. I just track its next position and shift audio data over it so the sound is not distorted.</p>
<p>So if you want to see metadata you should call the new constructor [[AudioStreamer alloc] initWithURL:[NSURL URLWithString:kLiveAudioLink] extractMetadata:YES] and subscribe to ASMetadataChangedNotification. Then use metadata property or -(NSDictionary *)parseMetadata call to get parsed strings.</p>
<p>You can find the fork of AudioStreamer code with these features here: <a href="https://github.com/dimzzy/AudioStreamer">https://github.com/dimzzy/AudioStreamer</a></p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/mRvqP0TaYwE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="255 http://www.dimzzy.com/blog/?p=255">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/09/audiostreamer-with-power-metering-and-icy-tags/</feedburner:origLink></item>
		<item>
		<title>Simple Editable Cell</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/18mzoFI9f3k/</link>
		<comments>http://www.dimzzy.com/blog/2011/08/simple-editable-cell/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 16:03:42 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=251</guid>
		<description><![CDATA[If you are using UITableView cell with style UITableViewCellStyleValue1 and wish it to be editable here is a simple implementation of the cell: BAEditableCell.h #import &#60;UIKit/UIKit.h&#62; @interface BAEditableCell : UITableViewCell @property(nonatomic, retain) UITextField *textField; @property(nonatomic, assign) CGFloat textFieldWidth; + (void)stopEditing:(UITableView *)tableView; @end BAEditableCell .m #import "BAEditableCell.h" #define kTextFieldDefaultWidth 180 @implementation BAEditableCell @synthesize textField, textFieldWidth; - [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using UITableView cell with style UITableViewCellStyleValue1 and wish it to be editable here is a simple implementation of the cell:</p>
<p><strong>BAEditableCell.h</strong></p>
<pre class="prettyprint">
#import &lt;UIKit/UIKit.h&gt;

@interface BAEditableCell : UITableViewCell

@property(nonatomic, retain) UITextField *textField;
@property(nonatomic, assign) CGFloat textFieldWidth;

+ (void)stopEditing:(UITableView *)tableView;

@end
</pre>
<p><strong> BAEditableCell .m</strong></p>
<pre class="prettyprint">
#import "BAEditableCell.h"

#define kTextFieldDefaultWidth 180

@implementation BAEditableCell

@synthesize textField, textFieldWidth;

- (void)dealloc {
    self.textField = nil;
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style
    reuseIdentifier:(NSString *)reuseIdentifier {
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.textField = [[[UITextField alloc] initWithFrame:CGRectZero] autorelease];
        self.textField.autoresizingMask = self.detailTextLabel.autoresizingMask;
        self.textField.font = [UIFont systemFontOfSize:17];
        self.textField.textColor = self.detailTextLabel.textColor;
        [self.contentView addSubview:self.textField];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    const CGFloat width = self.contentView.bounds.size.width;
    const CGFloat height = self.contentView.bounds.size.height;
    const CGFloat textWidth = self.textFieldWidth &gt; 0 ?
                      self.textFieldWidth : kTextFieldDefaultWidth;
    const CGFloat textHeight = self.textLabel.bounds.size.height;
    const CGFloat spacing = self.textLabel.frame.origin.x;
    self.textField.frame = CGRectMake(width - spacing - textWidth,
                                      (height - textHeight) / 2,
                                      textWidth, textHeight);
}

+ (void)stopEditing:(UITableView *)tableView {
    for (UITableViewCell *cell in [tableView visibleCells]) {
        if ([cell isKindOfClass:[BAEditableCell class]]) {
            BAEditableCell *editableCell = (BAEditableCell *)cell;
            [editableCell.textField resignFirstResponder];
        }
    }
}

@end
</pre>
<p>Here I just add text field over the details label, make it match the details label style and layout the cell appropriately. Method +stopEditing: is a convenience to hide the keyboard when user has entered all the data and wants to do something with it.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/18mzoFI9f3k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="251 http://www.dimzzy.com/blog/?p=251">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/08/simple-editable-cell/</feedburner:origLink></item>
		<item>
		<title>Cookie for UIView</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/0PwCQ1pcABQ/</link>
		<comments>http://www.dimzzy.com/blog/2011/08/cookie-for-uiview/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 17:20:41 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=247</guid>
		<description><![CDATA[Occasionally I have to associate some objects with UIViews for later use. Typically it's a UIButton: when it's touched I want to modify the associated object or to show it somewhere. And the usual solution is to rely on the 'tag' property of the view, using it as an index within array of the associated [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally I have to associate some objects with UIViews for later use. Typically it's a UIButton: when it's touched I want to modify the associated object or to show it somewhere. And the usual solution is to rely on the 'tag' property of the view, using it as an index within array of the associated objects or as a key in a map.</p>
<p>Here is a better way: in modern Objective C runtime (now it's almost everywhere) associated objects is a feature supported for all proper objects. So I've defined a category for UIView that adds 'cookie' property to all views using this runtime feature:</p>
<p><strong>UIView+BACookie.h</strong></p>
<pre class="prettyprint">
#import &lt;UIKit/UIKit.h&gt;

@interface UIView (UIView_BACookie)

@property(retain) id cookie;

@end
</pre>
<p><strong>UIView+BACookie.m</strong></p>
<pre class="prettyprint">
#import "UIView+BACookie.h"
#import &lt;objc/runtime.h&gt;

static char BAViewCookieKey;

@implementation UIView (UIView_BACookie)

- cookie {
    return objc_getAssociatedObject(self, &#038;BAViewCookieKey);
}

- (void)setCookie:cookie {
    objc_setAssociatedObject(self, &#038;BAViewCookieKey, cookie, OBJC_ASSOCIATION_RETAIN);
}

@end
</pre>
<p>Note that the cookie is retained when stored with the view and it will be automatically released when view is deallocated.</p>
<p>So now instead of dancing with 'tag' property or maintaining a custom map we could just stick our object into the view and use it when needed. And you could just copy this code to define your own properties for any other objects that you can't modify.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/0PwCQ1pcABQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="247 http://www.dimzzy.com/blog/?p=247">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/08/cookie-for-uiview/</feedburner:origLink></item>
		<item>
		<title>Show UIAlertView in one line</title>
		<link>http://feedproxy.google.com/~r/dimzzy/~3/vOlTCpcKxP4/</link>
		<comments>http://www.dimzzy.com/blog/2011/06/show-uialertview-in-one-line/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 12:16:35 +0000</pubDate>
		<dc:creator>dimzzy</dc:creator>
				<category><![CDATA[Apple]]></category>

		<guid isPermaLink="false">http://www.dimzzy.com/blog/?p=243</guid>
		<description><![CDATA[It may not be obvious but UIAlertView could be created and presented in one line of code. The reason is to avoid local variable to hold the view instance while it's created, displayed and autoreleased. Here is the code: [[[[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show]; To make things even simpler I define [...]]]></description>
			<content:encoded><![CDATA[<p>It may not be obvious but UIAlertView could be created and presented in one line of code. The reason is to avoid local variable to hold the view instance while it's created, displayed and autoreleased. Here is the code:</p>
<pre class="prettyprint">
[[[[UIAlertView alloc] initWithTitle:@"Title"
                             message:@"Message"
                            delegate:nil
                   cancelButtonTitle:@"OK"
                   otherButtonTitles:nil] autorelease] show];
</pre>
<p>To make things even simpler I define the following macro for the project:</p>
<pre>
#define BAAlert(TITLE,MSG) [[[[UIAlertView alloc] initWithTitle:(TITLE) \
              message:(MSG) \
             delegate:nil \
    cancelButtonTitle:@"OK" \
    otherButtonTitles:nil] autorelease] show]
</pre>
<p>Which could be used as simple call:</p>
<pre class="prettyprint">
BAAlert(@"Title", @"Message");
</pre>
<p>That's it.</p>
<img src="http://feeds.feedburner.com/~r/dimzzy/~4/vOlTCpcKxP4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss />
		<slash:comments><span class="dsq-postid" rel="243 http://www.dimzzy.com/blog/?p=243">0</span></slash:comments>
		<feedburner:origLink>http://www.dimzzy.com/blog/2011/06/show-uialertview-in-one-line/</feedburner:origLink></item>
	</channel>
</rss>

