Xcode indexing tip

April 12 2020 by Jeff Johnson

This is a tip to help Xcode find the proper documentation for the methods you use in your source code. Apparently Xcode needs a lot of help. I had implemented some Foundation framework methods in my code, but I was having trouble getting the documentation in Xcode. Option-clicking on the method declarations popped up popups that just said "No Quick Help", and command-clicking on the method declarations did not show the methods in the Foundation framework headers but rather did nothing other than momentarily change the highlight color of the method declarations in my source code. You've probably experienced this phenomenon before. It's ever so much fun! In this case, however, I found a solution.

Banging my head against the desk must have jarred something loose in my brain, because I suddenly realized that the problem may be related to protocol methods. I was using an NSURLSessionDataTask, and Xcode was having trouble with some delegate methods. The catch here is that NSURLSession takes a NSURLSessionDelegate, but if your delegate class only declares conformance to NSURLSessionDelegate, as required by the API, then Xcode doesn't necessarily recognize more specific protocol methods of NSURLSessionTaskDelegate and NSURLSessionDataDelegate. When I declared my delegate class as conforming to NSURLSessionDataDelegate instead, then suddenly Xcode could find the documentation and headers! My original declaration of conformance satisfied the compiler, as well as the runtime, but it failed to satisfy Xcode. Fickle as ever, Xcode!

Advice: If Xcode is having trouble finding docs for a framework method, check your protocol conformance. And if that doesn't work, never forget to check your references.

Jeff Johnson (My apps, PayPal.Me)