I’m getting a bit confused, so let me start over.
My question is in reference to the creation of a Singleton using the design pattern outlined in the BNR iOS book, Chapter 9. This is the same design pattern that Apple recommends here:
developer.apple.com/library/mac … jects.html
My question is simple… Do multiple init calls to an object present a problem. If so, does that suggest additional code is needed in the Chapter 9 example to prevent such?
If [BNRItemStore sharedStore] is called, all is happy. A singleton is created.
If BNRItemStore *myObject=[[BNRItemStore alloc]init] is called, the allocWithZone class method is called, referencing back to the sharedStore method. So in this case, init is called twice if a new object is created. If the object already exists, init is sent once to the new object via the original call.
In all cases, using [[BNRItemStore alloc]init], init is sent to an existing allocated and initialized object.
The allocWithZone method in the BNRItemStore class insures only one allocation. But, there is nothing that prevents multiple init calls.
There are two previous threads that asked this same question but I could not find a satisfying answer.
Sorry if I am overlooking the obvious.