<?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>favo &#187; Objective-C</title>
	<atom:link href="http://favo.asia/tag/objective-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://favo.asia</link>
	<description>Do you remember BTL? Beyond The Limitz? No? Too bad. – Oh, and I don`t tweet.</description>
	<lastBuildDate>Fri, 27 Jan 2012 17:33:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Time-based Kill-Switch for iOS Apps</title>
		<link>http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/</link>
		<comments>http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 14:21:36 +0000</pubDate>
		<dc:creator>favo</dc:creator>
				<category><![CDATA[Unsorted]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://favo.asia/?p=405</guid>
		<description><![CDATA[If you want to set your App to stop working at a specific date, you are thinking about a time-based Kill-Switch. You will want to do something like that if you worry about illegal copies of your Apps, you have sent out for testing purpose. Realizing such switch is very easy, here&#8217;s an example: NSDate [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://favo.asia/wp-content/uploads/2010/06/xcode.png"  rel="lightbox[405]"><img class="alignright size-full wp-image-216" title="XCode" src="http://favo.asia/wp-content/uploads/2010/06/xcode.png" alt="" width="150" height="150" /></a>If you want to set your App to stop working at a specific date, you are thinking about a time-based Kill-Switch.</p>
<p>You will want to do something like that if you worry about illegal copies of your Apps, you have sent out for testing purpose.</p>
<p>Realizing such switch is very easy, here&#8217;s an example:</p>
<pre name="code" class="c++">	NSDate *killDate = [NSDate dateWithTimeIntervalSinceNow:0];
	int killDateTs = [killDate timeIntervalSince1970];
	if ( killDateTs > 1280624461 ) { // 2010-08-01
		exit(0);
	}
</pre>
<p><br class="spacer_" /></p>
<p>Replace the timestamp with your own expire time and your App will stop working at that day.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-shr">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/&amp;title=Time-based+Kill-Switch+for+iOS+Apps" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/&amp;title=Time-based+Kill-Switch+for+iOS+Apps" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/&amp;bm_description=Time-based+Kill-Switch+for+iOS+Apps&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/&amp;title=Time-based+Kill-Switch+for+iOS+Apps" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/&amp;title=Time-based+Kill-Switch+for+iOS+Apps" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Time-based+Kill-Switch+for+iOS+Apps+-+http://95a.de/aR5rSu&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="display:none;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://favo.asia/2010/07/time-based-kill-switch-for-ios-apps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>UIScrollView and lazy loading</title>
		<link>http://favo.asia/2010/06/uiscrollview-and-lazy-loading/</link>
		<comments>http://favo.asia/2010/06/uiscrollview-and-lazy-loading/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 10:50:37 +0000</pubDate>
		<dc:creator>favo</dc:creator>
				<category><![CDATA[Unsorted]]></category>
		<category><![CDATA[Lazy Loading]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[UIScrollView]]></category>
		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://favo.asia/?p=206</guid>
		<description><![CDATA[If you have encountered memory problems loading too many images into your UIScrollView, lazy loading them is your answer.Lazy loading describes an easy technique to load only what should be shown, no more. Lazy loading of images in a UIScrollView is critical because of the iPhone/iPads/iPods low physical memory. Doing it on the other hand [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://favo.asia/wp-content/uploads/2010/06/xcode.png"  rel="lightbox[206]"><img class="alignleft size-medium wp-image-216" style="margin-right: 10px; margin-bottom: 10px;" title="XCode" src="http://favo.asia/wp-content/uploads/2010/06/xcode-300x300.png" alt="" width="180" height="180" /></a>If you have encountered memory problems loading too many images into your UIScrollView, lazy loading them is your answer.<br />Lazy loading describes an easy technique to load only what should be shown, no more.</p>
<p>Lazy loading of images in a UIScrollView is critical because of the iPhone/iPads/iPods low physical memory.</p>
<p>Doing it on the other hand is very easy if you follow these four steps:</p>
<p><b>1. Listen for scrollViewDidScroll on your delegate, like this:</b></p>
<pre name="code" class="c++">-(void)scrollViewDidScroll:(UIScrollView *)myScrollView {
}
</pre>
<p><br class="spacer_" /></p>
<p><b>2. Calculate the current page using the known size of your images:</b></p>
<pre name="code" class="c++">	/**
	 *	calculate the current page that is shown
	 *	you can also use myScrollview.frame.size.height if your image is the exact size of your scrollview
	 */
	int currentPage = (myScrollView.contentOffset.y / currentImageSize.height);
</pre>
<p><br class="spacer_" /></p>
<p><b>3. Look if the image already exists, if not, add it:</b></p>
<pre name="code" class="c++">	// display the image and maybe +/-1 for a smoother scrolling
	// but be sure to check if the image already exists, you can do this very easily using tags
	if ( [myScrollView viewWithTag:(currentPage +1)] ) {
		return;
	}
	else {
		// view is missing, create it and set its tag to currentPage+1
	}
</pre>
<p><br class="spacer_" /></p>
<p><b>4. And don&#8217;t forget to clean your memory:</b></p>
<pre name="code" class="c++">	/**
	 *	using your paging numbers as tag, you can also clean the UIScrollView
	 *	from no longer needed views to get your memory back
	 *	remove all image views except -1 and +1 of the currently drawn page
	 */
	for ( int i = 0; i < currentPages; i++ ) {
		if ( (i < (currentPage-1) || i > (currentPage+1)) &#038;&#038; [myScrollView viewWithTag:(i+1)] ) {
			[[myScrollView viewWithTag:(i+1)] removeFromSuperview];
		}
	}
</pre>
<p><br class="spacer_" /></p>
<p><b>= And the final combination of all steps:</b></p>
<pre name="code" class="c++">-(void)scrollViewDidScroll:(UIScrollView *)myScrollView {
	/**
	 *	calculate the current page that is shown
	 *	you can also use myScrollview.frame.size.height if your image is the exact size of your scrollview
	 */
	int currentPage = (myScrollView.contentOffset.y / currentImageSize.height);

	// display the image and maybe +/-1 for a smoother scrolling
	// but be sure to check if the image already exists, you can do this very easily using tags
	if ( [myScrollView viewWithTag:(currentPage +1)] ) {
		return;
	}
	else {
		// view is missing, create it and set its tag to currentPage+1
	}

	/**
	 *	using your paging numbers as tag, you can also clean the UIScrollView
	 *	from no longer needed views to get your memory back
	 *	remove all image views except -1 and +1 of the currently drawn page
	 */
	for ( int i = 0; i < currentPages; i++ ) {
		if ( (i < (currentPage-1) || i > (currentPage+1)) &#038;&#038; [myScrollView viewWithTag:(i+1)] ) {
			[[myScrollView viewWithTag:(i+1)] removeFromSuperview];
		}
	}
}
</pre>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-shr">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://favo.asia/2010/06/uiscrollview-and-lazy-loading/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://favo.asia/2010/06/uiscrollview-and-lazy-loading/&amp;title=UIScrollView+and+lazy+loading" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://favo.asia/2010/06/uiscrollview-and-lazy-loading/&amp;title=UIScrollView+and+lazy+loading" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://favo.asia/2010/06/uiscrollview-and-lazy-loading/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://favo.asia/2010/06/uiscrollview-and-lazy-loading/&amp;bm_description=UIScrollView+and+lazy+loading&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://favo.asia/2010/06/uiscrollview-and-lazy-loading/&amp;title=UIScrollView+and+lazy+loading" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://favo.asia/2010/06/uiscrollview-and-lazy-loading/&amp;title=UIScrollView+and+lazy+loading" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://favo.asia/2010/06/uiscrollview-and-lazy-loading/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=UIScrollView+and+lazy+loading+-+http://95a.de/b3reV4&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="display:none;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://favo.asia/2010/06/uiscrollview-and-lazy-loading/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

