<?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>IceTempest Development Studio &#187; macos</title>
	<atom:link href="http://icetempest.com/tag/macos/feed/" rel="self" type="application/rss+xml" />
	<link>http://icetempest.com</link>
	<description></description>
	<lastBuildDate>Mon, 12 Mar 2012 16:49:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Learning Cocoa</title>
		<link>http://icetempest.com/2010/04/learning-cocoa/</link>
		<comments>http://icetempest.com/2010/04/learning-cocoa/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 16:28:53 +0000</pubDate>
		<dc:creator>Sergio Moura</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[macos]]></category>

		<guid isPermaLink="false">http://icetempest.com/?p=211</guid>
		<description><![CDATA[So&#8230; Are you an experienced programmer and is moving to Cocoa? For either MacOS X or iPhone OS, the Cocoa Programming: A Quick-Start Guide for Developers book from the Pragmatic Bookshelf is a great addition to your library. It&#8217;s a great deal, wich i&#8217;ve just finished reading. The eBook costs $22.00 (US Dollars). It assumes [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://icetempest.com/wp-content/uploads/2010/04/dscpq.jpg"><img class="alignright size-full wp-image-214" title="Cocoa Programming: A Quick-Start Guide for Developers" src="http://icetempest.com/wp-content/uploads/2010/04/dscpq.jpg" alt="Book Cover" width="190" height="228" /></a>So&#8230; Are you an experienced programmer and is moving to Cocoa? For either MacOS X or iPhone OS, the<a href="http://www.pragprog.com/titles/dscpq/cocoa-programming" target="_blank"> Cocoa Programming: A Quick-Start Guide for Developers</a> book from the Pragmatic Bookshelf is a great addition to your library. It&#8217;s a great deal, wich i&#8217;ve just finished reading. The eBook costs $22.00 (US Dollars).</p>
<p>It assumes that you already know how to code, and is moving to a new platform (in this case Cocoa). It helped me a lot (and it still does) when I came from my C/C++ background to the MacOS Cocoa + ObjectiveC. It&#8217;s a hands-on approach that leaves no gaps in the explanations.  I&#8217;ve found myself many times coming from the Apple&#8217;s official tutorials to the eBook to get some clarification on some topics. It&#8217;s great both for learning and for reference.</p>
<p>If you&#8217;re new to programming and is starting in a MacOS platform, you can check out the <a href="http://www.pragprog.com/titles/tibmac/beginning-mac-programming" target="_blank">Beginning Mac Programming: Develop with Objective-C and Cocoa</a>. I haven&#8217;t read this one, but it seems to make the same approach from the first one, except it does not assume any programming background.</p>
<p>In the meantime, <a href="http://www.pragprog.com/wishlist/sergio-moura-61872-0ec4adbd90" target="_blank">my wishlist</a> is available with some other options of books (and, if you want to send me a gift, those are great ones).</p>
]]></content:encoded>
			<wfw:commentRss>http://icetempest.com/2010/04/learning-cocoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning to Search (+SQLite queries)</title>
		<link>http://icetempest.com/2010/03/learning-to-search/</link>
		<comments>http://icetempest.com/2010/03/learning-to-search/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 21:01:33 +0000</pubDate>
		<dc:creator>Sergio Moura</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[macos]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://icetempest.com/?p=115</guid>
		<description><![CDATA[Hello, Today I&#8217;m starting to write tutorials for iPhone, starting with a simple thing that took me a while to learn. How to make simple searches for iPhone and display it promptly in the search result? All the commands and screenshots below were taken on a MacOS X 10.6.2 with XCode 3.2.1 and iPhoneOS SDK [...]]]></description>
			<content:encoded><![CDATA[<p>Hello,</p>
<p>Today I&#8217;m starting to write tutorials for iPhone, starting with a simple thing that took me a while to learn. How to make simple searches for iPhone and display it promptly in the search result?</p>
<p>All the commands and screenshots below were taken on a MacOS X 10.6.2 with XCode 3.2.1 and iPhoneOS SDK 3.1.2.</p>
<p>I started by creating a database with common people names. I&#8217;ve found some common american names for <a href="http://names.mongabay.com/male_names.htm" target="_blank">male</a> and <a href="http://names.mongabay.com/female_names.htm" target="_blank">female</a>, wich I got the first 50 of each one, making a simple SQLite table, that you can get it from <a href="http://icetempest.com/files/people_names.sqlite.zip">here</a> (zipped for convenience).</p>
<p><span id="more-115"></span></p>
<p>The SQLite table structure is quite simple: it contains only one table names &#8220;names&#8221; with only one field named &#8220;name&#8221; (If you use MacOS X, you can check out the program <a href="http://menial.co.uk/software/base/" target="_blank">Base</a> to see the table structure).</p>
<p>So, start by creating a new iPhone project on XCode (window only) and name it whatever you like (I named mine &#8220;LearningToSearch&#8221;).</p>
<p><a href="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-3.34.40-PM.png"><img class="aligncenter size-thumbnail wp-image-117" title="Create new Window-based iPhone application" src="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-3.34.40-PM-150x150.png" alt="" width="150" height="150" /></a></p>
<p>With our project created, we should add the sqlite3.dylib in our project, as we&#8217;re going to read the database from a sqlite database file. Control-click the Frameworks Folder -&gt; Add -&gt; Existing Framework. From the list, select libsqlite3.dylib.</p>
<p>With that done, let&#8217;s move on on creating a table for display our data, but we need to create a TableView. For that, Create a new file. Menu File -&gt; New File&#8230; -&gt; iPhone OS/Cocoa Touch Class -&gt; UIViewController Subclass. Be sure to mark both checkboxes on Options (UITableViewController subclass and With XIB for user interface, as you can see in the screenshot below).</p>
<p><a href="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-3.40.11-PM.png"><img class="aligncenter size-thumbnail wp-image-118" title="Create new TableView" src="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-3.40.11-PM-150x150.png" alt="" width="150" height="150" /></a>Name it whatever you like. I named mine &#8220;SearchView&#8221;. It will create 3 files for you with extensions h, m and xib. We&#8217;re going to need a pointer to the TableView when doing our search, so, let&#8217;s create an outlet for holding it. In your SearchView.h file (or whatever you named it), add a variable and a property, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> SearchView <span style="color: #002200;">:</span> UITableViewController <span style="color: #002200;">&#123;</span>
	UITableView <span style="color: #002200;">*</span>myTableView;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic,retain<span style="color: #002200;">&#41;</span> IBOutlet UITableView <span style="color: #002200;">*</span>myTableView;</pre></div></div>

<p>That will hold our pointer to our myTableView that we&#8217;ll setup later on Interface Builder. Synthesize the getters and setters by adding the following code on SearchView.m after the @implementation line:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> myTableView;</pre></div></div>

<p>That&#8217;s it for now. We&#8217;ll be back for them later, let&#8217;s now setup some properties on the main application, add a import directive for our SearchView.h and getters and setters for our SearchView controller like we did with the table view. On &#8220;LearningToSearchAppDelegate.h&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;UIKit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &quot;SearchView.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> LearningToSearchAppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> &lt;UIApplicationDelegate&gt; <span style="color: #002200;">&#123;</span>
    UIWindow <span style="color: #002200;">*</span>window;
    SearchView <span style="color: #002200;">*</span>viewController;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIWindow <span style="color: #002200;">*</span>window;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet SearchView <span style="color: #002200;">*</span>viewController;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>With that, a synthesize in our .m file:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> viewController;</pre></div></div>

<p>That&#8217;s it we&#8217;ll come back later here too, but now let&#8217;s setup our interface.</p>
<p><strong>Setting up the interface</strong></p>
<p>Open MainWindow.xib in the Interface Builder (just double-click it).</p>
<p>You&#8217;ll get a blank interface screen with another window with 4 objects</p>
<p><a href="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-4.02.58-PM.png"><img src="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-4.02.58-PM-150x150.png" alt="" title="Blank Interface Builder window" width="150" height="150" class="aligncenter size-thumbnail wp-image-120" /></a><br />
<a href="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-4.02.54-PM.png"><img src="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-4.02.54-PM-150x150.png" alt="" title="Basic Interface Builder objects" width="150" height="150" class="aligncenter size-thumbnail wp-image-121" /></a></p>
<p>Next, we&#8217;ll add a UIViewController in our project. Select it and drag it along with the four other icons.</p>
<p>On &#8220;View Controller attributes&#8221; (Command-1) change NIB Name to &#8220;SearchView&#8221;<br />
<a href="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-5.09.08-PM.png"><img src="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-5.09.08-PM-150x150.png" alt="" title="Setting NIB Name" width="150" height="150" class="aligncenter size-thumbnail wp-image-122" /></a></p>
<p>And on &#8220;View Controller Identity&#8221; (Command-4), change the Class parameter to &#8220;Search View&#8221;<br />
<a href="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-5.11.04-PM.png"><img src="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-5.11.04-PM-150x150.png" alt="" title="Setup the Class Name" width="150" height="150" class="aligncenter size-thumbnail wp-image-123" /></a></p>
<p>Now, select &#8220;Learning To Search App Delegate&#8221; and link the viewController in the &#8220;Connection Inspectors&#8221; (Command-2) to the Search View Controller object.</p>
<p>We&#8217;re done with the main view. It does not much other then loading our SearchView. Save the file and open the &#8220;SearchView.xib&#8221; file. You&#8217;ll be presented with a table with some sample data.</p>
<p>Your window will have only three objects, the File&#8217;s Owner, First responder and Table View. We need to add a UISearchBar to the table. Just drag it from the Library to the Table. It&#8217;ll be positioned in the top of the table by default. Now, we just need to make two connections.</p>
<p>1) With the SearchBar selected, drag a link from &#8220;delegate&#8221; to the &#8220;File&#8217;s Owner&#8221; object. With this, we&#8217;re telling the SearchBar to send all events to our SearchView class.</p>
<p>2) With &#8220;File&#8217;s Owner&#8221; selected, drag a link from the &#8220;myTableView&#8221; outlet to the &#8220;Table View&#8221; object.</p>
<p>Our GUI setup is done. You can play around with the Search Bar parameters in the inspector, but nothing else is required for our sample to work.</p>
<p><strong>Setting up the code</strong></p>
<p>Now, to the code. We need to do some things:</p>
<p>1) Make our SearchView appear in the MainWindow (the links are set, but nobody told anyone to show it!);<br />
2) Load our database into an array;<br />
3) Setup the code for the table display our data<br />
4) Setup the search delegate (wich is the SearchView class) to understand and treat the Search Bar events.</p>
<p>Step 1:</p>
<p>This step is easy. Find the &#8220;LearningToSearchAppDelegate.m&#8221; file and add this line to the beggining of the &#8220;applicationDidFinishLaunching:&#8221; function:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span>viewController.view<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Note: If you run your program now, you should see an empty table with a search bar on the top.</p>
<p>Step 2:</p>
<p>On to the database.</p>
<p>Create two NSMutableArray variables on the SearchView.h file. One that will hold all our names, the other that will hold our search result (include these inside the brackets on the interface declaration).</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">	<span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>searchedNames;
	<span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span>names;</pre></div></div>

<p>No need to setup getters and setters for these, as we&#8217;re only going to use tem internally. We need to initialize our variables before we can use them. For that, we add the following lines in the &#8220;viewDidLoad&#8221; function (in the end of the function):</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">	names <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	searchedNames <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Now, to the hard part: Load the database and store all the data inside the names variable.<br />
Actually, that&#8217;s not hard at all, just copy that (hopefully documented) function below and place it in your SearchView implementation (no need to declare it on our header file, since we&#8217;re only going to use it internally):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>loadNames <span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">// Path to the database</span>
	<span style="color: #400080;">NSString</span><span style="color: #002200;">*</span> dbPath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> resourcePath<span style="color: #002200;">&#93;</span> stringByAppendingPathComponent<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;people_names.sqlite&quot;</span><span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;databasePath: %@&quot;</span>,dbPath<span style="color: #002200;">&#41;</span>;
	sqlite3 <span style="color: #002200;">*</span>database;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>name;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// Open the database</span>
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>sqlite3_open<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>dbPath UTF8String<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>database<span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> SQLITE_OK<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>sql <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">&quot;SELECT * FROM names&quot;</span>;
		sqlite3_stmt <span style="color: #002200;">*</span>compiledStmt;
		<span style="color: #11740a; font-style: italic;">// Fetch all names</span>
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>sqlite3_prepare_v2<span style="color: #002200;">&#40;</span>database, sql, <span style="color: #002200;">-</span><span style="color: #2400d9;">1</span>, <span style="color: #002200;">&amp;</span>compiledStmt, <span style="color: #a61390;">NULL</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> SQLITE_OK<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			<span style="color: #11740a; font-style: italic;">// Append each name</span>
			<span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span>sqlite3_step<span style="color: #002200;">&#40;</span>compiledStmt<span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> SQLITE_ROW<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
				<span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span><span style="color: #002200;">*</span> cName <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sqlite3_column_text<span style="color: #002200;">&#40;</span>compiledStmt, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
				<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cName <span style="color: #002200;">==</span> <span style="color: #a61390;">NULL</span><span style="color: #002200;">&#41;</span>
					<span style="color: #11740a; font-style: italic;">// There should not be a NULL name</span>
					NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Null name!!&quot;</span><span style="color: #002200;">&#41;</span>;
				<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
					name <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span>cName<span style="color: #002200;">&#93;</span>;
					<span style="color: #002200;">&#91;</span>names addObject<span style="color: #002200;">:</span>name<span style="color: #002200;">&#93;</span>;
					<span style="color: #11740a; font-style: italic;">// Apparently the addObject function in NSMutableArray does not</span>
					<span style="color: #11740a; font-style: italic;">// keep a copy of our object, so, we can't release it.</span>
					<span style="color: #11740a; font-style: italic;">//[name release];</span>
				<span style="color: #002200;">&#125;</span>
			<span style="color: #002200;">&#125;</span>
			sqlite3_finalize<span style="color: #002200;">&#40;</span>compiledStmt<span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// Cleanup the statement</span>
		<span style="color: #002200;">&#125;</span>
		<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
			NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Error retrieving data from database.&quot;</span><span style="color: #002200;">&#41;</span>;
		<span style="color: #002200;">&#125;</span>
		sqlite3_close<span style="color: #002200;">&#40;</span>database<span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
		NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Error: Can't open database!&quot;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Great! Now what about the database file? If you compile it as it is now, you&#8217;ll not read anything since our database is nowhere to be found. Drag the (unzipped) people_names.sqlite file to the &#8220;Resources&#8221; folder in XCode.</p>
<p>One more thing until we&#8217;re done with the SQLite part: we need to call our &#8220;loadNames&#8221; function. We&#8217;re going to alter our &#8220;viewDidLoad&#8221; function again. It&#8217;ll be like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
&nbsp;
	names <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	searchedNames <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>self loadNames<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Step 3:</p>
<p>Now we need to make our class respond to the TableView calls. Since we&#8217;re using the &#8220;searchedNames&#8221; array to store our data, we need to make sure we return the information from there. The TableView calls are quite self-explanatory, so, here goes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#pragma mark Table view methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>numberOfSectionsInTableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span><span style="color: #002200;">&#40;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>searchedNames count<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Set up the cell...</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>cellText <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>searchedNames objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>cell.textLabel setText<span style="color: #002200;">:</span>cellText<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>In short:<br />
* We have only one section<br />
* The number of lines is the same number of the searchedNames stored objects<br />
* When the table asks for a cell, we get the name of the object on the searchedNames and put it in the cell</p>
<p>Step 4:</p>
<p>Now to the sweet part. We need to answer the calls from the SearchBar. We want the &#8220;Search as we type&#8221; kind.</p>
<p>Here&#8217;s our full code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#pragma mark Search Functions</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>searchBarTextDidBeginEditing<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UISearchBar <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>searchBar <span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>searchBarTextDidEndEditing<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UISearchBar <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>searchBar <span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>searchBar<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UISearchBar <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>searchBar textDidChange<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>searchText <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>searchedNames removeAllObjects<span style="color: #002200;">&#93;</span>;<span style="color: #11740a; font-style: italic;">// remove all data that belongs to previous search</span>
	<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>searchText isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span><span style="color: #002200;">&#93;</span> || searchText<span style="color: #002200;">==</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #11740a; font-style: italic;">// Nothing to search, empty result.</span>
		<span style="color: #002200;">&#91;</span>myTableView reloadData<span style="color: #002200;">&#93;</span>;
		<span style="color: #a61390;">return</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>name <span style="color: #a61390;">in</span> names<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">NSRange</span> r <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>name rangeOfString<span style="color: #002200;">:</span>searchText options<span style="color: #002200;">:</span>NSCaseInsensitiveSearch<span style="color: #002200;">&#93;</span>;
		<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>r.location <span style="color: #002200;">!=</span> NSNotFound<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			<span style="color: #002200;">&#91;</span>searchedNames addObject<span style="color: #002200;">:</span>name<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#125;</span>
	<span style="color: #002200;">&#91;</span>myTableView reloadData<span style="color: #002200;">&#93;</span>;	
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>searchBarCancelButtonClicked<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UISearchBar <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>searchBar <span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>searchBarSearchButtonClicked<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UISearchBar <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>searchBar <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>searchBar resignFirstResponder<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Now, we don&#8217;t care when the user begin editing, ends editing or clicks the cancel button. We don&#8217;t really have a cancel button (unless you changed that), and we are using &#8220;on-the-go&#8221; searching.</p>
<p>The last function is important to make room when the user finishes searching. It disposes of the keyboard.</p>
<p>The &#8220;searchBar:textDidChange:&#8221; function is where we do our hardwork. We search in every item of our &#8220;names&#8221; arrange for an occurrence of the text in the SearchBar. Passing the option &#8220;NSCaseInsensitiveSearch&#8221;, we don&#8217;t mind for lower-case or upper-case letters.</p>
<p><strong>We&#8217;re done!</strong></p>
<p>Compile your project.</p>
<p>Check it our in your simulator.</p>
<p><a href="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-6.00.15-PM.png"><img src="http://icetempest.com/wp-content/uploads/2010/03/Screen-shot-2010-03-21-at-6.00.15-PM-161x300.png" alt="" title="We&#039;re done" width="161" height="300" class="aligncenter size-medium wp-image-125" /></a></p>
<p>Put it on your iPhone to play around on-the-go (if you have the license).</p>
<p>It took me a lot of searching to learn to do those, I hope you have less pain than me. Be sure to drop me a note if you have any questions.</p>
<p>Until next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://icetempest.com/2010/03/learning-to-search/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Currency Converter</title>
		<link>http://icetempest.com/2010/03/currency-converter/</link>
		<comments>http://icetempest.com/2010/03/currency-converter/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 21:18:25 +0000</pubDate>
		<dc:creator>Sergio Moura</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[macos]]></category>

		<guid isPermaLink="false">http://icetempest.com/?p=96</guid>
		<description><![CDATA[Check out the online currency converter for MacOS X. It was developed on Snow Leopard and targeted to Snow Leopard users. You can choose to work online or offline. When online, the program fetches the conversion rate from the internet and used for your conversions. Feedbacks and suggestions are welcome! Also, you like the software [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-99" title="Currency Converter Icon" src="http://icetempest.com/wp-content/uploads/2010/03/currency-logo-150x150.png" alt="" width="128" height="128" />Check out the online currency converter for MacOS X. It was developed on Snow Leopard and targeted to Snow Leopard users.</p>
<p>You can choose to work online or offline. When online, the program fetches the conversion rate from the internet and used for your conversions.<br />
<span id="more-96"></span><br />
Feedbacks and suggestions are welcome! Also, you like the software and want to show your appreciation, please, donate using the link below!</p>
<form style="text-align: center; " action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input name="cmd" type="hidden" value="_s-xclick" />
<input name="hosted_button_id" type="hidden" value="3BQD99LUA8WHA" />
<input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" type="image" /> <img src="https://www.paypal.com/en_US/i/scr/pixel.gif" border="0" alt="" width="1" height="1" /><br />
</form>
<p>Download for MacOSX 10.6:<br />
<a href="http://icetempest.com/files/Currency_1.0.zip"><img src="http://icetempest.com/wp-content/uploads/2010/02/save_64px.png" alt="" title="Download" width="64" height="64" class="size-full wp-image-70" /></a></p>
<p>Here are some screenshots:</p>
]]></content:encoded>
			<wfw:commentRss>http://icetempest.com/2010/03/currency-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Online Currency Converter for MacOS</title>
		<link>http://icetempest.com/2010/02/online-currency-converter-for-macos/</link>
		<comments>http://icetempest.com/2010/02/online-currency-converter-for-macos/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 17:06:53 +0000</pubDate>
		<dc:creator>Sergio Moura</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[macos]]></category>
		<category><![CDATA[online]]></category>

		<guid isPermaLink="false">http://icetempest.com/?p=57</guid>
		<description><![CDATA[An simple online currency converter application made for MacOS 10. This simple application lets you choose an target and destination currency from a predefined list and it convert the currencies for you. It fetches online the current convertion rate, displays it to you and the target value. It is very simple and plain. No in-depth [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://icetempest.com/wp-content/uploads/2010/02/Currency.png"><img class="alignright size-full wp-image-58" title="Currency Converter" src="http://icetempest.com/wp-content/uploads/2010/02/Currency.png" alt="" width="299" height="172" /></a></p>
<p>An simple online currency converter application made for MacOS 10. This simple application lets you choose an target and destination currency from a predefined list and it convert the currencies for you.<br />
It fetches online the current convertion rate, displays it to you and the target value.</p>
<p>It is very simple and plain. No in-depth work. Just saves you the time to go online, search the site and do the math by yourself.</p>
<p>I&#8217;ll post a download link later this week.</p>
]]></content:encoded>
			<wfw:commentRss>http://icetempest.com/2010/02/online-currency-converter-for-macos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

