<?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>Yonat Sharon</title>
	<atom:link href="http://ootips.org/yonat/feed/" rel="self" type="application/rss+xml" />
	<link>http://ootips.org/yonat</link>
	<description></description>
	<lastBuildDate>Sat, 24 Mar 2012 06:08:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Simple UIProgressHUD replacement</title>
		<link>http://ootips.org/yonat/simple-uiprogresshud-replacement/</link>
		<comments>http://ootips.org/yonat/simple-uiprogresshud-replacement/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 06:08:18 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=156</guid>
		<description><![CDATA[The private API UIProgressHUD shows an activity indicator (spinner) over a shaded round rect. Although you can use fancy and flexible replacements like MBProgressHUD, there is a simpler way if you don&#8217;t need all the extra functionality: Take a regular &#8230; <a href="http://ootips.org/yonat/simple-uiprogresshud-replacement/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://ootips.org/yonat/wp-content/uploads/2012/03/ActivityHUD.png" alt="" title="ActivityHUD" width="85" height="83" class="alignleft size-full wp-image-157" /><img src="http://ootips.org/yonat/wp-content/uploads/2012/03/ActivityHUDScreen.png" alt="" title="ActivityHUDScreen" width="198" height="372" class="alignright size-full wp-image-158" />The private API <a href="http://www.cocoadev.com/index.pl?UIProgressHUD" target="_blank">UIProgressHUD</a> shows an activity indicator (spinner) over a shaded round rect. Although you can use fancy and flexible replacements like <a href="http://github.com/matej/MBProgressHUD" target="_blank">MBProgressHUD</a>, there is a simpler way if you don&#8217;t need all the extra functionality: Take a regular <b>UIActivityIndicatorView</b> and add a partly transparent UIView behind it.</p>
<p>The simplest is to subclass of UIActivityIndicatorView so you can use it like any activity indicator.</p>
<p>The interface file:</p>
<pre class="brush: objc; title: ; notranslate">
//  ActivityHUD.h
#import &lt;UIKit/UIKit.h&gt;

@interface ActivityHUD : UIActivityIndicatorView
- (ActivityHUD *)initInView:(UIView *)view;
@end
</pre>
<p>And the implementation file:</p>
<pre class="brush: objc; title: ; notranslate">
//  ActivityHUD.m
#import &quot;ActivityHUD.h&quot;
#import &lt;QuartzCore/QuartzCore.h&gt;

@implementation ActivityHUD

- (ActivityHUD *)initInView:(UIView *)view
{
    self = [super initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    if (self) {
        // add background view
        CGFloat border = self.bounds.size.height / 2;
        CGRect hudFrame = CGRectInset(self.bounds, -border, -border);
        UIView *hud = [[UIView alloc] initWithFrame:hudFrame];
        hud.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.67];
        hud.layer.cornerRadius = border;
        [self addSubview:hud];
        [self sendSubviewToBack:hud];

        // center in parent view
        [view addSubview:self];
        self.center = [self convertPoint:view.center fromView:view];
    }
    return self;
}

@end
</pre>
<p>To use, init the <tt>ActivityHUD</tt> in a view, and later call <tt>startAnimating</tt> to show it, and <tt>stopAnimating</tt> to hide.</p>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/simple-uiprogresshud-replacement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Three Underscores Idiom</title>
		<link>http://ootips.org/yonat/the-three-underscores-idiom/</link>
		<comments>http://ootips.org/yonat/the-three-underscores-idiom/#comments</comments>
		<pubDate>Sat, 17 Mar 2012 07:15:27 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming Idioms]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=108</guid>
		<description><![CDATA[This is something I learned on my first programming job (eons ago&#8230;) and found useful but underused. Useful for what? To solve the persistent tension between the robustness of single-exit point and the complexity of using extra state variables and &#8230; <a href="http://ootips.org/yonat/the-three-underscores-idiom/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<pre class="brush: cpp; title: ; notranslate">
#define ___
// defines three underscores as nothing
</pre>
<p>This is something I learned on my first programming job (eons ago&#8230;) and found useful but underused.</p>
<p>Useful for what? To solve the persistent tension between the robustness of single-exit point and the  complexity of using extra state variables and state checking code.</p>
<p>Let me show you what I mean.</p>
<p><span id="more-108"></span>Say you write a function that needs to return an element matching some spec or create a new one. There are two ways to code this.</p>
<p>The simple yet multi-exit way:</p>
<pre class="brush: cpp; title: ; notranslate">
Element *matchingElement()
{
    for (Element *e  in collection) {
        if ( isMatching(e) ) {
            // some important code
            return e; // first exit point
        }
    }
    return newElement(); // second exit point
}
</pre>
<p>The single-exit way:</p>
<pre class="brush: cpp; title: ; notranslate">
Element *matchingElement()
{
    bool foundMatch = false;
    Element *e = getFirstElement();
    while (e != nil &amp;&amp; !foundMatch)
        if ( isMatching(e) ) {
            // some important code
            foundMatch = true; // setting state variable
        }
        e = nextElement();
    }
    return foundMatch ? e : newElement(); // single exit point from function
}
</pre>
<p>Now some of you are wondering why bother with foundMatch; you need to go read <a href="http://www.tomdalling.com/blog/coding-tips/coding-tip-have-a-single-exit-point">Tom Dalling&#8217;s Coding Tip explaining the problems with multiple exit points</a>.<br />
Others shudder to see a return statement in the middle of the function; you should remember that more variables mean more code mean more bugs.</p>
<p>So how does <em>the three underscores idiom</em> solve this conundrum? It goes hand in hand with the common convention of 4-space indentation. Together, they allow you to write this:</p>
<pre class="brush: cpp; title: ; notranslate">
Element *matchingElement()
{
    for (Element *e  in collection) {
        if (isMatching(e) ) {
            // some important code
___ ___ ___ return e;
        }
    }
___ return newElement();
}
</pre>
<p>And suddenly both exit points become clear and visible and not so prone to bugs.</p>
<p>The three underscores idiom should be used not only for return statements, but for any jump in the flow of control, like break or continue in a loop:</p>
<pre class="brush: cpp; title: ; notranslate">
Element *matchingElement()
{
    for (Element *e  in collection) {
        if ( notEvenClose(e) ) {
    ___ ___ continue;
        }
        if ( isMatching(e) ) {
            // some important code
___ ___ ___ return e;
        }
    } while ( e = nextElement() );
___ return newElement();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/the-three-underscores-idiom/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamic UIActionSheet</title>
		<link>http://ootips.org/yonat/filling-uiactionsheet-dynamically/</link>
		<comments>http://ootips.org/yonat/filling-uiactionsheet-dynamically/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 10:21:03 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Sample Code]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=129</guid>
		<description><![CDATA[Some actions may sometimes have more than one possible target, and other times only one. For example: Calling a contact. If the contact has just one phone number, you openURL with it and you&#8217;re done. But if she has several &#8230; <a href="http://ootips.org/yonat/filling-uiactionsheet-dynamically/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-130" title="message" src="http://ootips.org/yonat/wp-content/uploads/2012/02/message.png" alt="" width="240" height="212" />Some actions may sometimes have more than one possible target, and other times only one.</p>
<p>For example: Calling a contact. If the contact has just one phone number, you <strong>openURL</strong> with it and you&#8217;re done. But if she has several numbers, you want to open a <strong>UIActionSheet</strong> to let the user choose which number to call.</p>
<p><img class="size-medium wp-image-131 alignleft" title="photo" src="http://ootips.org/yonat/wp-content/uploads/2012/02/photo-200x300.png" alt="" width="200" height="300" />Or picking an image. If you&#8217;re running on a camera-less iPod, you just show a <strong>UIImagePickerController</strong> to pick from the photo library. But with a camera, and maybe an existing image to delete, you&#8217;ll want to show an action sheet to choose the actual action that your &#8220;Photo&#8221; button performs.</p>
<p>So you need to do two things:</p>
<ol>
<li>Decide whether to show an action sheet at all or just do the one possible action.</li>
<li>If you need an action sheet, fill it dynamically with the possible targets for action.</li>
</ol>
<p>The code to do that doesn&#8217;t have to be complicated. It can actually be as simple as this:</p>
<pre class="brush: objc; title: ; notranslate">
@interface MyViewController() : &lt;UIActionSheetDelegate&gt; {
	NSArray *possibleTargets; // action sheet buttons go here
}
@end

@implementation MyViewControllerMyViewController

- (IBAction)selectTargetForAction:(id)sender
{
    possibleTargets = SomeWayToFindPossibleTargets();

    if ([possibleTargets count] == 1) {
        // just call the one number, or show the one image picker
        [self doAction:[possibleTargets lastObject]];
    }
    else if ([possibleTargets count] &gt; 1) {
        // show a dynamically filled action sheet
        UIActionSheet *targetsSheet =
            [[UIActionSheet alloc] initWithTitle:__(@&quot;Select&quot;)
                delegate:self
                cancelButtonTitle:nil // since we want it last
                destructiveButtonTitle:nil
                otherButtonTitles:nil]; // since we can't hard-code them
        for (NSString *target in possibleTargets) {
            [targetsSheet addButtonWithTitle:__(target.title)];
        }
        targetsSheet.cancelButtonIndex = [targetsSheet addButtonWithTitle:__(@&quot;Cancel&quot;)];
        [targetsSheet showInView:self.view];
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != actionSheet.cancelButtonIndex) {
        [self doAction:[possibleTargets objectAtIndex:buttonIndex]];
    }
}

@end
</pre>
<p><b>Notes:</b></p>
<ol>
<li>The @interface code above is part of the .m file, as described in my earlier post <a href="http://ootips.org/yonat/objective-c-protocol-implementation/">How to Keep Your Protocols Private</a>.</li>
<li>If you&#8217;re puzzled by the meaning of <tt>__(@"String")</tt> then see my earlier post on <a href="http://ootips.org/yonat/easy-nslocalizedstring/">How To Make NSLocalizedString Fun To Use</a>.</li>
<li>The objects in possibleTargets can hold a selector (SEL) of the actual method to be executed, or they can hold just relevant data for the action (like a phone number to call).</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/filling-uiactionsheet-dynamically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reordering a UITableView</title>
		<link>http://ootips.org/yonat/reordering-a-uitableview/</link>
		<comments>http://ootips.org/yonat/reordering-a-uitableview/#comments</comments>
		<pubDate>Sat, 03 Mar 2012 20:35:15 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Sample Code]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=147</guid>
		<description><![CDATA[I like the simple and straightforward interface of the Reminders.app: edit reminders inline, and add a reminder by tapping and typing in the next empty line. So I wrote a UITableViewController subclass that does just that, but adds Edit mode &#8230; <a href="http://ootips.org/yonat/reordering-a-uitableview/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://ootips.org/yonat/wp-content/uploads/2012/02/EditableList.png" alt="" title="EditableList" width="374" height="358" class="alignright size-full wp-image-150" />I like the simple and straightforward interface of the Reminders.app: edit reminders inline, and add a reminder by tapping and typing in the next empty line. So I wrote a <b>UITableViewController</b> subclass that does just that, but adds Edit mode with reordering.</p>
<p>Coding reordering requires implementing methods from both of the two entangled protocols <b>UITableViewDataSource</b> and <b>UITableViewDelegate</b>.</p>
<p>In UITableViewDataSource we have the methods:<br />
<tt>tableView:<b>commitEditingStyle:</b>forRowAtIndexPath:</tt> (for insert and delete)<br />
<tt>tableView:<b>canMoveRowAtIndexPath:</b></tt> (for reorder)<br />
<tt>tableView:<b>moveRowAtIndexPath:</b>toIndexPath:</tt> (for reorder)</p>
<p>And in UITableViewDelegate:<br />
<tt>tableView:<b>editingStyleForRowAtIndexPath:</b></tt> (for insert and delete)<br />
<tt>tableView:<b>targetIndexPathForMoveFromRowAtIndexPath:</b>toProposedIndexPath:</tt> (for reorder)</p>
<p>The UITableViewDelegate methods are not strictly necessary in the simplest case where all rows are deletable, no row is insertable, and all rows are reorderable. In fact, in this simplest case you don&#8217;t need canMoveRowAtIndexPath either, only this:</p>
<pre class="brush: objc; title: ; notranslate">
- (void)tableView:(UITableView *)tableView
    moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
    toIndexPath:(NSIndexPath *)toIndexPath
{
    // Update the model with the change.
    // The view updates are already handled by UIKit.
}
</pre>
<p>But of course, if the last row (or the row past last) is an insert row, and is not reorderable, than you need to implement the other methods as well. You can get the code for that (along with the inline editable UITextField-s) at GitHub: <a href="http://github.com/yonat/EditableList">http://github.com/yonat/EditableList</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/reordering-a-uitableview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Keep Your Protocols Private</title>
		<link>http://ootips.org/yonat/objective-c-protocol-implementation/</link>
		<comments>http://ootips.org/yonat/objective-c-protocol-implementation/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 08:40:22 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Object Oriented Design]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming Idioms]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=118</guid>
		<description><![CDATA[Don&#8217;t you just hate when a small change in the innards of your view controller forces you to change its header file just to conform to a delegate protocol? For example, adding emailing functionality requires you to implement the MFMailComposeViewControllerDelegate &#8230; <a href="http://ootips.org/yonat/objective-c-protocol-implementation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t you just hate when a small change in the innards of your view controller forces you to change its header file just to conform to a <a href="https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/Delegation.html" target="_blank">delegate</a> protocol? For example, adding emailing functionality requires you to implement the <tt>MFMailComposeViewControllerDelegate</tt> protocol and <tt>@import &lt;MessageUI/MessageUI.h&gt;</tt>. Talk about breaking encapsulation&#8230;</p>
<p>Thankfully, you can do that in your .m implementation file instead. (Even though Apple sample code doesn&#8217;t.) All you need to do is use <b>the empty category</b>:</p>
<pre class="brush: objc; title: ; notranslate">
// MyViewController.m
#import &quot;MyViewController.h&quot;
#import &lt;MessageUI/MessageUI.h&gt;

@interface MyViewController ()
    &lt;MFMailComposeViewControllerDelegate&gt; // privately conform to protocol
@property (nonatomic, strong) UIView *somePrivateSubview;
@end

@implementation MyViewController
// synthesize and methods implementations
@end
</pre>
<p>The empty category <tt>MyViewController ()</tt> allows you to define private ivars, properties, methods, and even protocols – all in the privacy of your .m file, transparent to your clients.</p>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/objective-c-protocol-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BadgeLabel &#8211; Simple UILabel-based Badge</title>
		<link>http://ootips.org/yonat/badge-label/</link>
		<comments>http://ootips.org/yonat/badge-label/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 06:30:53 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Sample Code]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=103</guid>
		<description><![CDATA[I know, I know &#8211; not another badge class! But the thing is, the other badges laying around the net all seem overly complicated and too inflexible. So yes, I wrote another badge class. Luckily, it was really easy because &#8230; <a href="http://ootips.org/yonat/badge-label/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://ootips.org/yonat/wp-content/uploads/2012/02/badge.png" alt="" title="badge" width="368" height="385" class="alignright size-full wp-image-144" />I know, I know &#8211; not another badge class! But the thing is, the other badges laying around the net all seem overly complicated and too inflexible. So yes, I wrote another badge class. Luckily, it was really easy because I used the built-in capabilities of iOS, and it turned out very flexible and powerful, because, well, I used the built-in capabilities of iOS. No manual CoreGraphics drawing code, just automatic CALayer-s magic.</p>
<p>The basic badge is a <tt>UILabel</tt> whose underlying <tt>CALayer</tt> has a <tt>backgroundColor</tt> and <tt>cornerRadius</tt>:</p>
<pre class="brush: objc; title: ; notranslate">
#import &lt;QuartzCore/QuartzCore.h&gt; // don't forget!
// ...
UILabel *badge = [[UILabel alloc] init];
badge.layer.backgroundColor = [UIColor blueColor].CGColor;
badge.layer.cornerRadius = badge.bounds.size.height / 2;
</pre>
<p>Basically, that&#8217;s it. There are some adjustments needed to make sure the label leaves enough space around the text for the rounded corners, but that&#8217;s easily done with short overrides of <tt>textRectForBounds</tt> and <tt>drawTextInRect</tt>.</p>
<p>The nice thing is how easy it is to make app-icon style badges, with border, shadow and gloss:</p>
<ul>
<li>For <b>border</b> simply set the layer&#8217;s <tt>borderColor</tt> and <tt>borderWidth</tt>.</li>
<li>For <b>shadow</b> set the layer&#8217;s <tt>shadowOpacity</tt>, <tt>shadowColor</tt> and <tt>shadowOffset</tt>.</li>
<li>For <b>gloss</b> add a <tt>CAGradientLayer</tt> sublayer.</li>
</ul>
<p>It&#8217;s that simple. And even better: animatable!</p>
<p>You can get the code, along with a Mail.app style <tt>BadgeTableViewCell</tt> and a demo app, at GitHub: <a href="http://github.com/yonat/BadgeLabel">http://github.com/yonat/BadgeLabel</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/badge-label/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Render UIView to UImage</title>
		<link>http://ootips.org/yonat/render-uiview-to-uimage/</link>
		<comments>http://ootips.org/yonat/render-uiview-to-uimage/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 05:35:49 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Sample Code]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=100</guid>
		<description><![CDATA[There&#8217;s a simple way to render a UIView into a UIImage: use the view&#8217;s layer, and render it into a bitmap graphic context. Here is the code, phrased as a UIView category: Just remember to link the QuartzCore.framework and you&#8217;re &#8230; <a href="http://ootips.org/yonat/render-uiview-to-uimage/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a simple way to render a UIView into a UIImage: use the view&#8217;s <strong>layer</strong>, and render it into a bitmap graphic context. Here is the code, phrased as a UIView category:</p>
<pre class="brush: objc; title: ; notranslate">
#import &quot;UIView+RenderUIImage.h&quot;
#import &lt;QuartzCore/QuartzCore.h&gt;

@implementation UIView (RenderUIImage)

- (UIImage *)renderAsImage
{
    // setup context
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0f); // use same scale factor as device
    CGContextRef c = UIGraphicsGetCurrentContext();

    // render view
    [self.layer renderInContext:c];

    // get reslting image
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return result;
}

@end
</pre>
<p>Just remember to link the QuartzCore.framework and you&#8217;re good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/render-uiview-to-uimage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Make NSLocalizedString Fun To Use</title>
		<link>http://ootips.org/yonat/easy-nslocalizedstring/</link>
		<comments>http://ootips.org/yonat/easy-nslocalizedstring/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 07:00:37 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming Idioms]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=72</guid>
		<description><![CDATA[To localize apps (which means: to make them work in other languages) you need to avoid using plain @&#8221;strings&#8221; and instead use the one of the tedious functions NSLocalizedString, NSLocalizedStringFromTable, or NSLocalizedStringFromTableInBundle, that take two to four arguments. Horror. I &#8230; <a href="http://ootips.org/yonat/easy-nslocalizedstring/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To localize apps (which means: to make them work in other languages) you need to avoid using plain @&#8221;strings&#8221; and instead use the one of the tedious functions <strong>NSLocalizedString</strong>, <strong>NSLocalizedStringFromTable</strong>, or <strong>NSLocalizedStringFromTableInBundle</strong>, that take two to <em>four</em> arguments. Horror.</p>
<p>I mean, any sane programmer will get a headache from replacing a simple <tt>@"Great!"</tt> with this:</p>
<pre class="brush: objc; title: ; notranslate">
NSLocalizedStringFromTable(@&quot;Great!&quot;, @&quot;Messages&quot;, nil)
</pre>
<p>So I took <a href="http://codex.wordpress.org/Function_Reference/_2" target="_blank">a leaf from WordPress</a>, and shortened the calls:</p>
<pre>#define __(str) NSLocalizedStringFromTable(str, @"Messages", nil)
#define __d(str, description) NSLocalizedStringFromTable(str, @"Messages", description)</pre>
<p>Now localization is easy and fun: I simply type
<pre class="brush: objc; title: ; notranslate">__(@&quot;Great!&quot;)</pre>
<p> and the localization code is taken care of by the C pre-processor. Mission accomplished.</p>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/easy-nslocalizedstring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Store UIImage in CoreData Without Writing Any Code</title>
		<link>http://ootips.org/yonat/uiimage-in-coredata/</link>
		<comments>http://ootips.org/yonat/uiimage-in-coredata/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 17:13:53 +0000</pubDate>
		<dc:creator>Yonat Sharon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CoreData]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://ootips.org/yonat/?p=64</guid>
		<description><![CDATA[There is an easy but little known way to store many kinds of UIKit objects in CoreData without writing any code. It works for UIImage, UIColor, UIBezierPath, MKPlaceMark, NSDate, and any other class that conforms to the NSCoding protocol. What &#8230; <a href="http://ootips.org/yonat/uiimage-in-coredata/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-66" title="NSUnarchiveFromDataTransformerName" src="http://ootips.org/yonat/wp-content/uploads/2012/01/NSUnarchiveFromDataTransformerName.png" alt="" width="264" height="257" />There is an easy but little known way to store many kinds of UIKit objects in CoreData without writing any code. It works for UIImage, UIColor, UIBezierPath, MKPlaceMark, NSDate, and any other class that conforms to the <strong>NSCoding</strong> protocol.</p>
<p>What you need to do is set the attribute type to <strong>Transformable</strong>, and the the transformable name to <strong>NSUnarchiveFromDataTransformerName</strong>.</p>
<p>That&#8217;s it!</p>
<p>Now can set UIImage objects directly into your NSManagedObject objects:</p>
<pre class="brush: objc; title: ; notranslate">
person.thumbnailImage = [UIImage imageNamed:@&quot;defaultPortrait&quot;];
anImageView.image = person.thumbnailImage;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ootips.org/yonat/uiimage-in-coredata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

