This won't work?

Discussion in 'Mac Programming' started by larswik, Aug 24, 2010.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    I get 14 errors and the first one is in the @implementation "error: Rectangle.h no such file or directory"??? When I go to MENU and select FILE and select NEW FILE and then select OBJECTIVE C CLASS I get 2 files a '.h' and '.m'. Can I name these what ever I want or do I have to name them the same as project? I did try to name it the same thing as the project file and then it asked me if I wanted to overwrite the existing 'Rectangle.m' file?
    Code:
    #import <Foundation/Foundation.h.>
    
    @interface Rectangle : NSObject 
    {
    	int width;
    	int height;	
    }
    @property int width, height;
    
    -(void) area;
    -(void) perimeter;
    -(void) setWidth: (int) w andHeight: (int) h;
    @end
    
    Code:
    #import "Rectangle.h"
    
    
    @implementation Rectangle
    @synthesize width, height;
    -(void) area
    {
    return width * height;
    }
    -(void) perimeter
    	
    {
    return (width + height) * 2;
    }
    		
    -(void) setWidth: (int) w andHeight: (int) h
    {
    width = w;
    height = h;
    }
    @end
    Code:
    #import "Rectangle.h"
    #import <stdio.h>
    
    int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    	
    	Rectangle *myRect = [[Rectangle alloc] init];
    	
    	[myRect setWidth: 5 andHeight: 8];
    	NSLog(@"w = %i, h = %i", myRect.widthm myRect.height);
    	NSLog(@"Area = %i, Peramiter = %i",[myRect area, myRect Peramiter]);
    	
    	[myRect release];
    	
        [pool drain];
        return 0;
    }
    
     
  2. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #2
    Never mind. I think this is supposed to be linked to another file.

    Thanks.
     

Share This Page