pdenlinger
pdenlinger

Reputation: 3917

'@end' is missing in implementation context

Have two errors which relate to implementation. Have commented out the errors.

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

Implementation file:

#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

Upvotes: 0

Views: 1569

Answers (1)

MByD
MByD

Reputation: 137382

You forgot to close the if block

if (self) {

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

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

Upvotes: 6

Related Questions