Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 错误:没有属性声明_Objective C - Fatal编程技术网

Objective c 错误:没有属性声明

Objective c 错误:没有属性声明,objective-c,Objective C,我在头文件中声明了两个属性,并在类(名称?)文件中合成了这两个属性: 宽度 高度 (哈希/磅符号)导入 .m文件: (hash/pound symbol)import "Rectangle.h" @implementation Rectangle @synthesize width, height; -(void) setWidth: (int) w setHeight: (int) h { width = w; height = h; } -(int) area {

我在头文件中声明了两个属性,并在类(名称?)文件中合成了这两个属性:

  • 宽度
  • 高度

    (哈希/磅符号)导入

.m文件:

 (hash/pound symbol)import "Rectangle.h"
@implementation Rectangle

@synthesize width, height;
-(void) setWidth: (int) w setHeight: (int) h
{
    width = w;
    height = h;
}
-(int) area
{
    return width * height;
}
-(int) perimeter
{
    return (width + height) * 2;
}
@end
但是,我得到了一些错误:

请原谅我对“#”符号和代码格式有问题。

我很惊讶

@property width, height;
。。。这甚至可以编译。应该是:

@property int width;
@property int height;
你几乎永远不会看到这个:

-(void) setWidth: (int) w setHeight: (int) h;
相反,@property意味着
setWidth:
setHeight:

我很惊讶

@property width, height;
。。。这甚至可以编译。应该是:

@property int width;
@property int height;
你几乎永远不会看到这个:

-(void) setWidth: (int) w setHeight: (int) h;
相反,@property意味着
setWidth:
setHeight:

尝试以下操作:

@interface Rectangle : NSObject 
{   
  int width;  
  int height; 
}

@property int width;
@property int height;

-(int) area;
-(int) perimeter;
-(void) setWidth: (int) w andHeight: (int) h;

@end
试试这个:

@interface Rectangle : NSObject 
{   
  int width;  
  int height; 
}

@property int width;
@property int height;

-(int) area;
-(int) perimeter;
-(void) setWidth: (int) w andHeight: (int) h;

@end

@属性int高度、宽度@克松谢对。这就是为什么我感到惊讶,甚至编译。。。这就是OP的代码。@属性int height,width@克松谢对。这就是为什么我感到惊讶,甚至编译。。。这是OP的密码。