此Expected expression
错误对此代码行的含义是什么:
[super setNilValueForKey:key];
代码:
#import "Person.h"
@implementation Person
- (id) init
{
self = [super init];
expectedRaise = 5.0;
personName = @"New Person";
return self;
}
- (void)dealloc
{
[personName release];
[super dealloc];
}
- (void)setNilValueForKey:(NSString *)key
{
if ([key isEqual:@"expectedRaise"])
{
[self setExpectedRaise:0.0];
}
else
{
[super setNilValueForKey:key];
}
}
@synthesize personName;
@synthesize expectedRaise;
@end
·H:
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
NSString *personName;
float expectedRaise;
}
@property (readwrite, copy) NSString *personName;
@property (readwrite) float expectedRaise;
@end
答案 0 :(得分:0)
如果你真的有
[super setNilValueForKey:<#key#>];
在您的代码中,解决方案应该像
一样简单[super setNilValueForKey:key];
答案 1 :(得分:0)
isEqual
是错误的方法,因为我想比较字符串值isEqualToString
是正确的。
- (void)setNilValueForKey:(NSString *)key
{
if ([key isEqualToString:@"expectedRaise"])
{
[self setExpectedRaise:0.0];
}
else
{
[super setNilValueForKey:key];
}
}