Not surprisingly, Xcode is able to autocomplete the parameters to the separate 
function.

Here’s my whole routine:

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let config = NSURLSessionConfiguration.defaultSessionConfiguration()

        let url = NSURL(string: "http://www.somewebservice 
<http://www.somewebservice/>.com")
        let session = NSURLSession(configuration: config)

        let request = NSURLRequest(URL: url!)

        var task = session.dataTaskWithRequest(request) {
            data, response, error in

            let httpResponse = response as! NSHTTPURLResponse

            if httpResponse.statusCode == 200 {

                let teams: AnyObject? = 
NSJSONSerialization.JSONObjectWithData(data, options: 
NSJSONReadingOptions.AllowFragments, error: nil)
                
                println(teams)
            }
            
        }
        task.resume()

    }

Paste this into a new project, and click after the “in” and see if Xcode 
recognizes “data”, “response”, or “error” when you start typing. Oddly, after 
you enter the keyword, you can option-click to have Xcode show you the correct 
type, and typing a “.” will give you the autocomplete popup.

Thanks.



> On Mar 9, 2015, at 7:00 PM, LCS <[email protected]> wrote:
> 
> Hello...
> 
> There doesn’t seem to be anything wrong with your line of code, but there 
> could be a problem somewhere else (or with how/where you’re writing the code 
> for the completion handler block).
> 
> I’ve run into problems a few times where the compiler didn’t report errors 
> properly or gave cryptic error messages, but I was usually able to figure out 
> my mistake by breaking out the offending line into individual statements so 
> that I got a better error message from the compiler (except for one time, 
> where a mistake in declaring a function compiled cleanly and then later on 
> segfaulted the compiler when it was called; 19437380).
> 
> To isolate the problem, I’d try declaring the completion handler function 
> separately and then pass in the function.
> 
> func testHandler(myData: NSData!, myResponse: NSURLResponse!, myError: 
> NSError!) -> Void
> {
>     // try your handler code here
>      
> }
>     
> let task = session.dataTaskWithRequest(request, completionHandler: 
> testHandler)
> 
> If Xcode accepts your handler code that way and accepts the function as a 
> parameter, you might have a mistake in how you’re adding your handler code to 
> the inline closure in the line you posted. If you post the code showing how 
> you are adding the handler code to the original line you posted, we could 
> rule that out.
> 
>      Louis

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to