2012-04-23 94 views
0

有兩個與實現有關的錯誤。已經評論了錯誤。實現上下文中缺少'@end'

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 
+0

不是一個Xcode的問題 – Almo 2012-04-23 20:32:12

回答

6

你忘了關,如果塊

if (self) { 

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

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

感謝您捕捉的是,它的工作! – pdenlinger 2012-04-23 20:40:52

+0

好吧,早幾分鐘出現同樣的問題,確實有幫助;) – MByD 2012-04-23 21:00:23