使用未声明的标识符

时间:2014-03-11 05:54:30

标签: objective-c macos cocoa

我是Objective-C编码的新手,请耐心问我是否这是一个简单的问题 我的头文件:

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*) response;

@end

我的实施档案:

#import "AppDelegate.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    NSMutableData *receivedData  =[NSMutableData dataWithCapacity: 0];

    // Create the request
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"] cachePolicy:NSURLRequestUseProtocolCachePolicy
                                      timeoutInterval:60.0];

    // Create the NSMutableData to hold the received data.
    // receivedData is an instance variable declared elsewhere.                  
    receivedData = [NSMutableData dataWithCapacity: 0];

    // create the connection with the request
    // and start loading the data
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if (!theConnection) {
        // Release the receivedData object.
        receivedData = nil;
        // Inform the user that the connection failed.
     }
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSMutableData *receivedData =[NSMutableData dataWithCapacity:0];


    // This method is called when the server has determined that it
    // has enough information to create the NSURLResponse object.

    // It can be called multiple times, for example in the case of a
    // redirect, so each time we reset the data.

    // receivedData is an instance variable declared elsewhere.
    [receivedData setLength:0];
}
@end

当我在实现appDelegate运行代码时,它会发出警告

  

连接的方法定义:didRecieveResponse:not found

  

- (void)连接线,它给出了“使用未检查的标识符连接,你的意思是收集”。

1 个答案:

答案 0 :(得分:0)

您无需声明方法

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*) response; 
如果您在代码中使用NSURLConnectionDataDelegate协议,则在头文件中

。只需在实现中添加协议并使用该协议中的方法。