Use of undeclared identifier Objective-C Code

12,430

As you can see in the comment:

// receivedData is an instance variable declared elsewhere.
receivedData = [NSMutableData dataWithCapacity: 0];

receivedData should be declared somewhere. Try this:

NSMutableData *receivedData = [NSMutableData dataWithCapacity: 0];
Share:
12,430
Pritesh Patel
Author by

Pritesh Patel

enthusiastic learner of programming languages

Updated on June 04, 2022

Comments

  • Pritesh Patel
    Pritesh Patel about 2 years

    I am new to Objective-C coding ,please bear with me to ask if this is simple question

    My Header file:

    #import <Cocoa/Cocoa.h>
    
    @interface AppDelegate : NSObject <NSApplicationDelegate>
    @property (assign) IBOutlet NSWindow *window;
    
    @end
    

    My Implementation file:

    #import "AppDelegate.h"
    
    @implementation AppDelegate
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {    
        // Insert code here to initialize your application
    
        // Listing 2-1  Creating a connection using NSURLConnection
    
        // 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.
        }
    }
    
    @end
    

    at receivedData in implementation file it is showing undeclared identifier. if declare that variable in .h file its saying cannot declare variable inside @interface and protocol

  • Pritesh Patel
    Pritesh Patel over 10 years
    should i declare it in header file or implementation file
  • Antonio MG
    Antonio MG over 10 years
    Depending on the visibility you want, in the header file is public, in the implementation will be private.