I’m trying to add a convenience constructor to my custom object.
Similar to [NSArray arrayWithArray:]
I know it involves a class method that returns an auto released object. I’ve been googling around but all I can seem to find is the definition of a convenience constructor but not how to write one.
Let’s say you have the following:
Then to add a factory method, you’d change it to this:
And your implementation would simply be:
Edit: replaced
idwithinstancetype. They are functionally identical, but the latter provides better hints to the compiler about the method’s return type.