R
R
Ruslan Bergutov2015-10-26 11:00:50
Objective-C
Ruslan Bergutov, 2015-10-26 11:00:50

How to put the result of NSURLSession dataTask into a variable with type NSData?

NSData* data = [session dataTaskWithRequest:request];

The compiler complains about data type incompatibility:
Incompatible pointer types initializing 'NSData' with an expression of type 'NSURLSessionDataTask'

I tried to fix it by casting the data type, but it didn’t work out.
I’m a beginner, so don’t rule out that I’m a crook

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AmikoYuki, 2015-10-26
@AmikoYuki

Read a book on obj-c, or google, finally, you don’t need to fantasize.
You do not even try to understand, but whine that no one is helping you.

[[_session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        //ТУТ ВАШ КОД ДЕЛАЙТЕ С data что душе угодно.
    }] resume];

// Либо так:
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

There are a lot of options in the documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question