What is the syntax and use of a factory method in Objective-C
If we take UIColor
as an example, factory methods would be + (UIColor *)blackColor
, + (UIColor *)clearColor
, ...
From the other question you reference, any init...
method should be an instance method (- (...)
, not + (...)
). In that answer it is a class method and it shouldn't be.
Are factory methods what are called constructors in other languages
They all have the same purpose. Not all languages differentiate between allocation of memory and initialisation of that memory.
How are factory methods compared to Singletons
A singleton usually offers a single method to return the single instance of the class. It isn't strictly a factory method as it doesn't create a different instance each time it's called, but it is the same kind of thing.