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
On Mar 5, 2015 John Tsombakos <email@hidden <mailto:email@hidden>> wrote:
Well it was a nice though, but the session variable is created with:
let session = NSURLSession(configuration: config)
And it’s not an optional (just a NSURLSession type) , so that theory is out :(
> On Mar 5, 2015, at 2:28 PM, John Tsombakos <email@hidden
> <mailto:email@hidden>> wrote:
>
> I will have to check it when I get home, that sounds plausible. However it
> build and runs just fine. But with all the Swift-y oddness, I'm not surprised
> by anything. (Of course, the SourceKit service shouldn't crash either, so...)
>
> Thanks.
>
> On Thu, Mar 5, 2015 at 1:54 PM, Fritz Anderson <email@hidden
> <mailto:email@hidden>> wrote:
> On 5 Mar 2015, at 6:24 AM, John Tsombakos <email@hidden
> <mailto:email@hidden>> wrote:
>
>> I entered this line of code:
>>
>> let task = session.dataTaskWithRequest(request, completionHandler: {
>> (myData, myResponse, myError) -> Void in
>>
>>
>>
>> });
>>
>> and when I go to write code in the completion handler block, Xcode does not
>> recognize the variables that are being passed in - in this case myData,
>> myResponse and myError.
>>
>> Ami I doing something wrong, or does XCode just not know how to do this?
>
> Quincey’s advice is sound as to the coding style. Let me embarrass myself
> once again; I’m working my way up to total humiliation, which gets you BOGO
> on all Developer Programs renewals and the exemption of your choice from the
> app-review guidelines:
>
> My experience is that when the compiler claims not to recognize a function
> parameter, it’s because something up the chain isn’t unwrapped (such as
> session, here).
>
> — F
_______________________________________________
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]