0

有两个与实施有关的错误。已注释掉错误。

Header file: 
#import <Foundation/Foundation.h>

@interface Appliance : NSObject {
  NSString *productName;
  int voltage;
}

@property (copy)NSString *productName;
@property int voltage;
-(id)initWithProductName:(NSString *)pn;

@end

实现文件:

#import "Appliance.h"

@implementation Appliance //'@end' is missing in implementation context

@synthesize productName, voltage;

-(id)initWithProductName:(NSString *)pn
{
  // Call the NSObject's init method
  self = [super init];

  // Did it return something non-nil?
  if (self) {

    // Set the product name
    [self setProductName:pn];

    // Give voltage a starting value
    [self setVoltage:120];

  // Return a pointer to the new object
  return self;
}
@end // unexpected '@' in program
4

1 回答 1

6

你忘了关闭 if 块

if (self) {

    // Set the product name
    [self setProductName:pn];

    // Give voltage a starting value
    [self setVoltage:120];
} // << missing
于 2012-04-23T20:32:33.170 回答