我在NSString上写了以下类别:
@interface NSString (Checks)
-(BOOL) isUppercase;
-(BOOL) containsStr: (NSString *) str;
@end;
@implementation NSString (Checks)
-(BOOL) isUppercase
{ return [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[self characterAtIndex:0]]
}
-(BOOL) containstStr: (NSString *) str
{ return [self rangeOfString:str].location != NSNotFound;
}
@end
我缺少方法声明的上下文,期望的方法体,@ end必须出现在.h文件中的Objective C上下文错误中,为什么会这样?
答案 0 :(得分:0)
@end
之后你不应该有分号。还要确保导入Foundation框架:
#import <Foundation/Foundation.h>
@interface NSString (Checks)
- (BOOL)isUppercase;
- (BOOL)containsStr:(NSString *)str;
@end
#import "NSString+Checks.h" // or whatever your .h is called.
@implementation NSString (Checks)
- (BOOL)isUppercase {
return [[NSCharacterSet uppercaseLetterCharacterSet]
characterIsMember:[self characterAtIndex:0]];
}
- (BOOL)containsStr:(NSString *)str {
return [self rangeOfString:str].location != NSNotFound;
}
@end