Question

I have ubuntu machine and compiling objective-c using GNUStep. I wrote the following code:

#import <objc/objc.h>
#import <Foundation/Foundation.h>
#import <objc/NSArray.h>


int main ( int argc, char ** argv)
{
  int ar[100] = {0};
  int i;
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  NSArray *arr = [[NSArray alloc] initWithObjects:@"stackOverflow", @"1", @"2", nil];
  NSLog (@ "Counts in the array %i", [arr count]);

  @try {
    NSString *str;
    str = [arr objectAtIndex:1];
    NSLog (@" String value is %@ ", str);
  }
  @catch (NSRangeException * excep)
  {
    NSLog (@"Reached Range caught for %@:%@" [excep name], [excep reason]); 
  }

  [pool release];
}

But I get the following fatal error:

fatal error: objc/NSArray.h: No such file or directory

I tried <NSArray.h> also, but getting same error. Which path I have to provide?

Was it helpful?

Solution

The file objc/NSArray.h does not exist, hence the fatal error.

Remove the #import <objc/NSArray.h> as NSArray should already be available via the Foundation import.

See https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top