Note that there are some explanatory texts on larger screens.

plurals
  1. POPossible to return an object into a completion block?
    primarykey
    data
    text
    <p>I work with Core data and I want to call a function for returning an object. This object is completed in this function with AFNetworking into a completion block. I want to know if it's possible to return this object into this completion block... for use it later. Failed code here, because newMember in completion block is not allowed and not working.</p> <p>This error appears : <code>Incompatible block pointer types sending 'Member *(^)(NSURLRequest...'</code></p> <pre><code>+(Member *)returnMemberModelWithId:(NSString *)myid withContext:(NSManagedObjectContext *)managedObjectContext{ __block NSMutableArray *dicoNe =[[NSMutableArray alloc] init]; __block Member *newMember = [NSEntityDescription insertNewObjectForEntityForName:@"Member" inManagedObjectContext:managedObjectContext]; NSString *s= @".json"; NSString *str = [NSString stringWithFormat: @"%@%@", myid, s]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://epnet.fr/"]]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; [httpClient setParameterEncoding:AFFormURLParameterEncoding]; NSString *path = [NSString stringWithFormat:@"members/%@", str]; NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:path parameters:nil]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *innerRequest, NSHTTPURLResponse *response, id reponseJSON) { dicoNe = reponseJSON; NSNumber *v = [dicoNe valueForKey:@"id"]; newMember.idMember = v; //And others assignments .. return newMember; // It's not working } failure:^(NSURLRequest *innerRequest, NSHTTPURLResponse *response, NSError *error, id reponseJSON) { NSLog(@"Fail %@", reponseJSON); }]; [operation start]; return newMember; } </code></pre> <p>So , my object newMember which I try to return is null at the end. So my question is, how can I return my object completed by AFN with this function? Many thanks</p>
    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.
 

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