I am somewhat lost on how to declare properties in my Singleton. Should I use strong or weak? Particularly I have an NSMutableArray property and I am not sure what to do. Can someone explain in some what detail?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This has nothing to do with Singletons, and depends entirely on how your array is being used. Is it private? Public? Readonly? Readwrite? It just depends on ownership, like everything else. If your singleton owns the array, use
strongorcopy. Otherwise useweak.That said, it’s not typically a good idea to directly expose a mutable collection at all. If you only need other classes to be able to read it, use an
NSMutableArrayinternally, and expose anNSArraycopy publicly. If other classes need to mutate the collection, it’s better practice to expose a set of KVC-compliant methods that mutate an internal mutable array.