如果我同时调用 [[RKClient sharedClient] get@“foo.xml";delegate:self] 在两个 UIViewController 中? [英] What will be if I call simultaneously [[RKClient sharedClient] get@"foo.xml" delegate:self] in two UIViewControllers?

查看:27
本文介绍了如果我同时调用 [[RKClient sharedClient] get@“foo.xml";delegate:self] 在两个 UIViewController 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在两个 UIViewController 中同时调用 [[RKClient sharedClient] get@"foo.xml" delegate:self] 会怎样?我有什么问题吗?

What will be if I calls simultaneously [[RKClient sharedClient] get@"foo.xml" delegate:self] in two UIViewControllers? Do I have any problems?

viewController_A
{
[[RKClient sharedClient] get:@"foo.xml" delegate:self];
}

viewController_B
{
 [[RKClient sharedClient] get:@"foo.xml" delegate:self];
}

推荐答案

如果您查看 get:delegate: 的 RKClient 实现,它就可以做到这一点

If you have a look at the RKClient implementation for get:delegate: it simply does this

- (RKRequest *)get:(NSString *)resourcePath delegate:(id)delegate {
    return [self load:resourcePath method:RKRequestMethodGET params:nil delegate:delegate];
}

load:method:params:delegate: 的实现是

- (RKRequest *)load:(NSString *)resourcePath method:(RKRequestMethod)method params:(NSObject<RKRequestSerializable> *)params delegate:(id)delegate {
    NSURL* resourcePathURL = nil;
    if (method == RKRequestMethodGET) {
        resourcePathURL = [self URLForResourcePath:resourcePath queryParams:(NSDictionary*)params];
    } else {
        resourcePathURL = [self URLForResourcePath:resourcePath];
    }
    RKRequest *request = [[RKRequest alloc] initWithURL:resourcePathURL delegate:delegate];
    [self setupRequest:request];
    [request autorelease];
    request.method = method;
    if (method != RKRequestMethodGET) {
        request.params = params;
    }

    [request send];

    return request;
}

它没有使用任何 RKClient 状态/共享数据,因此您不会看到问题.get:delegate: 方法本身是异步的,所以这些东西无论如何都会在后台发生.

It's not using any RKClient state / shared data so you won't see a problem. The method get:delegate: is asynchronous itself so this stuff will happen in the background anyway.

这篇关于如果我同时调用 [[RKClient sharedClient] get@“foo.xml";delegate:self] 在两个 UIViewController 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆