Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are on the right track. And the application delegate is a great place for a socket connection. I think you're being tripped up by something relatively simple.</p> <p><code>[[UIApplication sharedApplication] delegate]</code> returns an <code>id</code> or generic object pointer to an object that conforms to the <code>&lt;UIApplicationDelegate&gt;</code> protocol. So code completion has no way of knowing that your application's delegate is an instance of <em>your</em> <code>AppDelegate</code> class.</p> <p>Remember if you are in fact using an instance of <code>AppDelegate</code> to be your application's delegate then <code>[[UIApplication sharedApplication] delegate]</code> will return a pointer to your delegate, but it will be the generic pointer discussed above.</p> <p>The simplest solution is to cast the pointer you receive back from <code>[[UIApplication sharedApplication] delegate]</code> to be a pointer of <code>AppDelegate</code> type. </p> <p>For example:</p> <pre><code>AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; // We now have a pointer to your app delegate that the compiler knows is an AppDelegate. // So code completion will work and it will compile. GCDAsyncSocket *socket = [myAppDelegate asyncSocket]; </code></pre> <p>Or you can stack the calls to one statement. The syntax looks a little funky, but this is how it's done.</p> <pre><code>GCDAsyncSocket *socket = [(AppDelegate *)[[UIApplication sharedApplication] delegate] asyncSocket]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload