AFNetworking的异步get怎么传出数据?

AFNetworking没有同步get,如果我要把获取的数据传出get函数应该怎么做?

异步的话还没等到查询结束就执行下一条语句了。

AFHTTPRequestOperationManager*mananger = [AFHTTPRequestOperationManagermanager];
mananger.responseSerializer= [AFHTTPResponseSerializerserializer];
[manangerPOST:@“http://xxxxx?uid=123"parameters:nilsuccess:^(AFHTTPRequestOperation*operation,idresponseObject) {
NSDictionary*dic = [NSJSONSerializationJSONObjectWithData:responseObjectoptions:NSJSONReadingMutableContainerserror:nil];
saveDic= dic;
model= [[AccoundModelalloc]init];
[modelsetValuesForKeysWithDictionary:dic];
NSLog(@"%@",model);

    [selfinitData:model];


}failure:^(AFHTTPRequestOperation*operation,NSError*error) {

}];

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

AFHTTPRequestOperationManager*manager = [AFHTTPRequestOperationManagermanager];
manager.responseSerializer= [AFHTTPResponseSerializerserializer];

//@"uid" @"totalAmount" @"singleAmount" @"validityTime" @"miniDueTime" @"maxDueTime" @"miniRatePy" @"maxRatePy"

[saveDicsetObject:@“123"forKey:@"uid"];
[managerPOST:@“http://xxxx"parameters:saveDicsuccess:^(AFHTTPRequestOperation*operation,idresponseObject) {
   NSDictionary*dic = [NSJSONSerializationJSONObjectWithData:responseObjectoptions:NSJSONReadingMutableContainerserror:nil];

   NSLog(@"%@",dic);

}failure:^(AFHTTPRequestOperation*operation,NSError*error) {

}];

在get的异步回调函数中,可以通过闭包拿到self,然后通过self调用自定义函数

[saveDicsetObject:@“123"forKey:@"uid"];
[managerPOST:@“http://xxxx"parameters:saveDicsuccess:^(AFHTTPRequestOperation*operation,idresponseObject) {
NSDictionary*dic = [NSJSONSerializationJSONObjectWithData:responseObjectoptions:NSJSONReadingMutableContainerserror:nil];

NSLog(@"%@",dic);

}failure:^(AFHTTPRequestOperation*operation,NSError*error) {

}];

业务上有需要的话写个阻塞 直到获取到需要的值后 在下一步调用

可以用信号量去控制,可以尝试一下

使用代码块或者闭包进行数据返回就解决了!
/// 超时时间设置
lazy var sessionManager:Alamofire.SessionManager = {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 5
return Alamofire.SessionManager(configuration: configuration)
}()

func getListData(apiStr:String, finshedBlock:@escaping (_ resoult:Any) -> Void) -> Void {
    self.sessionManager.request(apiStr, method: .get).responseJSON { (resoult) in
        let json = resoult.result.value
        finshedBlock(json ?? "error")
    }
}