<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Cocoa Touch on A&#43; programming moments</title>
    <link>https://aplus.rs/tags/cocoa-touch/</link>
    <description>Recent content in Cocoa Touch on A&#43; programming moments</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sat, 09 Jan 2010 01:28:10 +0000</lastBuildDate>
    
	<atom:link href="https://aplus.rs/tags/cocoa-touch/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Always use isEqualToString for string comparisons</title>
      <link>https://aplus.rs/2010/always-use-isequaltostring-for-string-comparisons/</link>
      <pubDate>Sat, 09 Jan 2010 01:28:10 +0000</pubDate>
      
      <guid>https://aplus.rs/2010/always-use-isequaltostring-for-string-comparisons/</guid>
      <description>&lt;p&gt;While working on my iPhone app &lt;a href=&#34;http://radianttap.com/quickie/&#34;&gt;Quickie&lt;/a&gt;, I encountered one of many examples why you must &lt;em&gt;always check your code on the actual device&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Quickie uses Core Data for storage and in one particular place I was comparing the &lt;code&gt;NSString&lt;/code&gt; variable to a &lt;code&gt;NSString&lt;/code&gt;-typed property of my CoreData class, &lt;code&gt;QuickieList&lt;/code&gt;. Like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-objectivec&#34; data-lang=&#34;objectivec&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;QuickieList&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;listName&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;theListName&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;listName&lt;/code&gt; is defined as &lt;code&gt;NSString&lt;/code&gt; and &lt;code&gt;theListName&lt;/code&gt; is obviously that as well. In this particular instance, both of those had the value of &amp;ldquo;test&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;In the iPhone Simulator (running on 10.6.2) this comparison returned &lt;code&gt;false&lt;/code&gt;, but on the iPhone running 3.1.2 it returned &lt;code&gt;true&lt;/code&gt;. When changed into:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-objectivec&#34; data-lang=&#34;objectivec&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;QuickieList&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;listName&lt;/span&gt; &lt;span class=&#34;nl&#34;&gt;isEqualToString&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;theListName&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;result was the same.&lt;/p&gt;
&lt;p&gt;Never &amp;ndash; I repeat &amp;ndash; &lt;em&gt;never&lt;/em&gt; assume that simulator testing will be fine, even for seemingly small things. It can bite you when you least expect it.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>UITextField.text is not always there</title>
      <link>https://aplus.rs/2010/uitextfield-text-is-not-always-there/</link>
      <pubDate>Wed, 06 Jan 2010 10:25:59 +0000</pubDate>
      
      <guid>https://aplus.rs/2010/uitextfield-text-is-not-always-there/</guid>
      <description>&lt;p&gt;If you have UITextField on the page and you need to validate is there something in it (so if yes you can save the input or something), you might do something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-objectivec&#34; data-lang=&#34;objectivec&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;addNewCellTextField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;nl&#34;&gt;isEqualToString&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;err&#34;&gt;…&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However, this will fail if the field is never touched. That is, until your user taps the field and it gets focus, UITextField.text is nil. Which means that condition above yields true, which is not what you want.&lt;/p&gt;
&lt;p&gt;Once it is touched though, this becomes an instance of NSString with value of @&amp;quot;&amp;quot;. Thus, always use:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-objectivec&#34; data-lang=&#34;objectivec&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;addNewCellTextField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!=&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;nil&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;addNewCellTextField&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;text&lt;/span&gt; &lt;span class=&#34;nl&#34;&gt;isEqualToString&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;err&#34;&gt;…&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Watch out for this little trap hole.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>