<?xml version='1.0' encoding='utf-8' ?>

<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>A Story of Coincidence and Chance</title>
  <link>https://bcholmes.dreamwidth.org/</link>
  <description>A Story of Coincidence and Chance - Dreamwidth Studios</description>
  <lastBuildDate>Thu, 04 Jul 2019 03:19:58 GMT</lastBuildDate>
  <generator>LiveJournal / Dreamwidth Studios</generator>
  <lj:journal>bcholmes</lj:journal>
  <lj:journaltype>personal</lj:journaltype>
  <image>
    <url>https://v2.dreamwidth.org/85477/119236</url>
    <title>A Story of Coincidence and Chance</title>
    <link>https://bcholmes.dreamwidth.org/</link>
    <width>83</width>
    <height>100</height>
  </image>

<item>
  <guid isPermaLink='true'>https://bcholmes.dreamwidth.org/811832.html</guid>
  <pubDate>Thu, 04 Jul 2019 03:19:58 GMT</pubDate>
  <title>Getting Closer</title>
  <link>https://bcholmes.dreamwidth.org/811832.html</link>
  <description>&lt;p&gt;&lt;a href=&quot;https://blog.bcholmes.org/wp-content/uploads/2019/07/Simulator-Screen-Shot-iPhone-Xʀ-2019-07-03-at-23.14.11.png&quot;&gt;&lt;img class=&quot;alignnone size-medium wp-image-2018&quot; src=&quot;https://blog.bcholmes.org/wp-content/uploads/2019/07/Simulator-Screen-Shot-iPhone-Xʀ-2019-07-03-at-23.14.11-139x300.png&quot; alt=&quot;&quot; width=&quot;139&quot; height=&quot;300&quot; srcset=&quot;https://blog.bcholmes.org/wp-content/uploads/2019/07/Simulator-Screen-Shot-iPhone-Xʀ-2019-07-03-at-23.14.11-139x300.png 139w, https://blog.bcholmes.org/wp-content/uploads/2019/07/Simulator-Screen-Shot-iPhone-Xʀ-2019-07-03-at-23.14.11-768x1662.png 768w, https://blog.bcholmes.org/wp-content/uploads/2019/07/Simulator-Screen-Shot-iPhone-Xʀ-2019-07-03-at-23.14.11-473x1024.png 473w, https://blog.bcholmes.org/wp-content/uploads/2019/07/Simulator-Screen-Shot-iPhone-Xʀ-2019-07-03-at-23.14.11.png 828w&quot; sizes=&quot;(max-width: 139px) 100vw, 139px&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Almost.&lt;/p&gt;
&lt;p style=&quot;text-align: right&quot;&gt;&lt;small&gt;Mirrored from &lt;a href=&quot;https://blog.bcholmes.org/getting-closer/&quot; title=&quot;Read Original Post&quot;&gt;Under the Beret&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=bcholmes&amp;ditemid=811832&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://bcholmes.dreamwidth.org/811832.html</comments>
  <category>objective-c</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
<item>
  <guid isPermaLink='true'>https://bcholmes.dreamwidth.org/729874.html</guid>
  <pubDate>Wed, 27 Jun 2012 01:54:50 GMT</pubDate>
  <title>Objective-C Oddities</title>
  <link>https://bcholmes.dreamwidth.org/729874.html</link>
  <description>&lt;p&gt;I was tweaking a bit of Objective-C code the other day, and stumbled upon one of those situations that seemed like it should be straight-forward, but which bit me.  Consider the following.&lt;/p&gt;
&lt;p&gt;My app is downloading some information in a background thread.  Here&amp;#8217;s my code:&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;c-sharp&quot;&gt;
NSData *data = [NSURLConnection sendSynchronousRequest:request 
                   returningResponse:&amp;#038;response error:error];
if (error != nil) {
    NSLog(@&quot;error : %@&quot;, error.localizedDescription);
} else {
    
    // check response code, etc.
    ...
}  
&lt;/pre&gt;
&lt;p&gt;The code compiled fine, but when I ran it, I would sometimes get an EXC_BAD_ACCESS crash.  Turns out, the Cocoa APIs are designed to communicate information via the response type, as &lt;a href=&quot;http://stackoverflow.com/questions/7883089/nserror-exc-bad-access&quot; rel=&quot;external&quot;&gt;StackOverflow&lt;/a&gt; clarified for me.  According to the Apple Error Handling standards:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;you should always check that the return value is nil or NO before attempting to do anything with the NSError object.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;So I&amp;#8217;d needed to write:&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;c-sharp&quot;&gt;
NSData *data = [NSURLConnection sendSynchronousRequest:request 
                   returningResponse:&amp;#038;response error:error];
if (data != nil) {
    // check response code, etc.
    ...
} else if (error != nil) {
    NSLog(@&quot;error : %@&quot;, error.localizedDescription);
}  
&lt;/pre&gt;
&lt;p&gt;At some level, this type of error feels wrong.  I&amp;#8217;ve got a non-nil error object; it&amp;#8217;s just in a state that I can&amp;#8217;t use it.  It feels to me like there&amp;#8217;s something messed up with the way the API works.&lt;/p&gt;
&lt;p&gt;But whatever. Data first; error second.&lt;/p&gt;
&lt;p style=&quot;text-align: right&quot;&gt;&lt;small&gt;Mirrored from &lt;a href=&quot;http://blog.bcholmes.org/objective-c-oddities/&quot; title=&quot;Read Original Post&quot;&gt;Under the Beret&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=bcholmes&amp;ditemid=729874&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://bcholmes.dreamwidth.org/729874.html</comments>
  <category>objective-c</category>
  <category>cocoa</category>
  <lj:security>public</lj:security>
  <lj:reply-count>0</lj:reply-count>
</item>
</channel>
</rss>
