iOS error: No visible @interface for 'xxxx' declares the selector 'alloc'

My psychic debugger, without reading your code, tells me you're calling alloc on an object instance, rather than a class. The alloc method is a static method defined by classes (typically inherited from NSObject) that returns a new instance of the underlying object. You can't ask an instance to allocate itself!

Now looking at the code, I see that you want:

self.myValidator = [[TextValidator alloc] init];

to construct a new instance, and assign it to the myValidator property.


Replace

[[self.myValidator alloc] init];

with

self.myValidator = [[TextValidator alloc] init];

The error signals that you have not implemented the alloc instance method for self.myValidator, which is true. But that's a class method that applies for all NSObject objects.