这是我的TextValidator类:
//TextValidator.h #import <Foundation/Foundation.h> @interface TextValidator : NSObject - (BOOL) isValidPassword:(NSString *)checkPassword; - (BOOL) isValidEmail:(NSString *)checkString; - (BOOL) isEmpty:(NSString *)checkString; @end // TextValidator.m #import "TextValidator.h" @implementation TextValidator - (BOOL) isEmpty:(NSString *)checkString { return YES; } - (BOOL) isValidPassword:(NSString *)checkPassword { return YES; } - (BOOL) isValidEmail:(NSString *)checkString { return YES; } @end
这是我尝试在ViewController.m中初始化TextValidator类的方法:
//ViewController.h #import <Foundation/Foundation.h> @interface SignUpViewController : UIViewController <UITextFieldDelegate> @end //ViewController.m #import "SignUpViewController.h" #import "TextValidator.h" @interface SignUpViewController () @property TextValidator *myValidator; @end @implementation SignUpViewController - (void)viewDidLoad { [[self.myValidator alloc] init]; //iOS error: No visible @interface for 'TextValidator' declares the selector 'alloc'* [super viewDidLoad]; } @end
No visible @interface for 'TextValidator' declares the selector 'alloc'.
TextValidator类继承自NSObject,据我所知,init和alloc函数已在基类中定义.那么为什么程序会出现这样的错误呢?