However, because of the id return type in +factoryMethodB, the compiler can give no warning about the y line. Since an object of type id can be any class, and since a method called -count exists somewhere on some class, to the compiler it’s possible that the return value of +factoryMethodB implements the method.
To make sure instancetype factory methods have the right subclassing behavior, be sure to use [self class] when allocating the class rather than referring directly to the class name. Following this convention ensures that the compiler will infer subclass types correctly. For example, consider trying to do this with a subclass of MyObject from the previous example: