用于在AFNetworking2中调用类方法的块语法

时间:2013-12-07 21:19:59

标签: objective-c objective-c-blocks afnetworking-2

这是一个总的noob问题,但我正在测试AFNetworking2,特别是UIWebView + AFNetworking。但是我如何调用loadRequest。我有:

    NSURL *websiteUrl = [NSURL URLWithString:@"http://www.google.com"];  //fine
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];  //find


   [self.myWebView loadRequest:urlRequest progress:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))^{ // do I need second carat?
        //NSLog(@"writing bytes %i", bytesWritten);  // how to get access to bytesWritten?
        NSLog(@"writing bytes");

    }....

但是我想要NSLog的bytesWritten。块语法总是抛出一个循环。我需要拨打第二个克拉吗?

以下是该电话的文档链接:http://cocoadocs.org/docsets/AFNetworking/2.0.3/Categories/UIWebView+AFNetworking.html

2 个答案:

答案 0 :(得分:2)

这是正确的语法

[self.myWebView loadRequest:urlRequest progress:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite)){ 
    NSLog(@"writing bytes %lu", (unsigned long)bytesWritten);
}];

参考文献:

答案 1 :(得分:1)

“第二克拉”约为。 400毫克。你要找的是“插入符号”。


这是传递文字块的方式:

[Foo doStuff:^(T1 arg1, T2 arg2) {
    // and this is how you use the arguments:
    NSLog(@"Arg 2: %@", arg2);
}];