I’m getting the hang of iOS and working with the different frameworks. My project is getting more complex (of course) and I think I am doing some stuff in a convoluted way.
I’m wondering if there is a simpler design pattern to handle this situation:
App with lots of properties held in an array; also holds NSDictionary of NSDictionaries representing the options for each property.
Property Editor: presents table displaying current properties with edit option for detail view
Detail View: displays table with all the options for a particular property
I’ve got this working now by:
App -> sets itself as delegate to Property Editor which accesses the delegate’s (App’s) current properties and the arrays of property options
Property Editor -> sets itself as delegate for each Detail view and sets property on Detail View representing appropriate array of property options from delegate
Detail View -> appropriate array of property options
This seems pretty convoluted. Would it be better to make the Detail View delegate my App? Is there a design pattern which is clearer? I realize that there is tight coupling between all these classes but I don’t see how that is avoidable.
Why not create a singleton class for accessing all your app properties (let’s call it
PropertiesContainer). This class will hold the necessary dictionaries and will be accessed by[PropertiesContainer sharedInstance].This way all the classes you mentioned don’t need to be coupled with each one to access the properties. Now you will have one class which is easily accessed wherever you need it. (and it does not need to know who uses it)