<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dw="https://www.dreamwidth.org">
  <id>tag:dreamwidth.org,2009-04-24:119236</id>
  <title>A Story of Coincidence and Chance</title>
  <subtitle>BC Holmes</subtitle>
  <author>
    <name>BC Holmes</name>
  </author>
  <link rel="alternate" type="text/html" href="https://bcholmes.dreamwidth.org/"/>
  <link rel="self" type="text/xml" href="https://bcholmes.dreamwidth.org/data/atom"/>
  <updated>2019-07-04T03:22:21Z</updated>
  <dw:journal username="bcholmes" type="personal"/>
  <entry>
    <id>tag:dreamwidth.org,2009-04-24:119236:811832</id>
    <link rel="alternate" type="text/html" href="https://bcholmes.dreamwidth.org/811832.html"/>
    <link rel="self" type="text/xml" href="https://bcholmes.dreamwidth.org/data/atom/?itemid=811832"/>
    <title>Getting Closer</title>
    <published>2019-07-04T03:19:58Z</published>
    <updated>2019-07-04T03:22:21Z</updated>
    <category term="objective-c"/>
    <dw:security>public</dw:security>
    <dw:reply-count>0</dw:reply-count>
    <content type="html">&lt;p&gt;&lt;a href="https://blog.bcholmes.org/wp-content/uploads/2019/07/Simulator-Screen-Shot-iPhone-Xʀ-2019-07-03-at-23.14.11.png"&gt;&lt;img class="alignnone size-medium wp-image-2018" src="https://blog.bcholmes.org/wp-content/uploads/2019/07/Simulator-Screen-Shot-iPhone-Xʀ-2019-07-03-at-23.14.11-139x300.png" alt="" width="139" height="300" srcset="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" sizes="(max-width: 139px) 100vw, 139px" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Almost.&lt;/p&gt;
&lt;p style="text-align: right"&gt;&lt;small&gt;Mirrored from &lt;a href="https://blog.bcholmes.org/getting-closer/" title="Read Original Post"&gt;Under the Beret&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=bcholmes&amp;ditemid=811832" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
  <entry>
    <id>tag:dreamwidth.org,2009-04-24:119236:729874</id>
    <link rel="alternate" type="text/html" href="https://bcholmes.dreamwidth.org/729874.html"/>
    <link rel="self" type="text/xml" href="https://bcholmes.dreamwidth.org/data/atom/?itemid=729874"/>
    <title>Objective-C Oddities</title>
    <published>2012-06-27T01:54:50Z</published>
    <updated>2012-07-03T03:20:32Z</updated>
    <category term="cocoa"/>
    <category term="objective-c"/>
    <dw:security>public</dw:security>
    <dw:reply-count>0</dw:reply-count>
    <content type="html">&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="code" class="c-sharp"&gt;
NSData *data = [NSURLConnection sendSynchronousRequest:request 
                   returningResponse:&amp;#038;response error:error];
if (error != nil) {
    NSLog(@"error : %@", 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="http://stackoverflow.com/questions/7883089/nserror-exc-bad-access" rel="external"&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="code" class="c-sharp"&gt;
NSData *data = [NSURLConnection sendSynchronousRequest:request 
                   returningResponse:&amp;#038;response error:error];
if (data != nil) {
    // check response code, etc.
    ...
} else if (error != nil) {
    NSLog(@"error : %@", 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="text-align: right"&gt;&lt;small&gt;Mirrored from &lt;a href="http://blog.bcholmes.org/objective-c-oddities/" title="Read Original Post"&gt;Under the Beret&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=bcholmes&amp;ditemid=729874" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
</feed>
