Reputation: 1175
I started to develop my singleton class but I have a problem. What I want to do is have a search objects containing the values of the search form that I could use in several views. I want to have the ability to get the singleton in any view in order to perform the search or build the search form. So I have a set of values with a boolean for each to know if the variable has been initialized by the user or not, cause not all the search fields needs to be filled in.
For example :
NSString name= Bob;
BOOL nameFilled =True;
NSString adress= nil;
BOOL adressFilled=false;
NSNumber numberOfChilds = 0;
BOOL numberOfChildsFilled = false;
So my problem is that I can't retain the boolean in my header file because it's not a class. How can I do, is there a better solution than what I presented above? Hope I have been clear
Upvotes: 0
Views: 407
Reputation: 25969
Seriously, don't implement a singleton. It isn't necessary for this application. You should have a model class to handle this.
Try using dependancy injection and/or plist files to save the information. You'll have a much better time debugging and extending functionality.
Upvotes: 0
Reputation: 24040
Instead of using int, use NSNumber. Then, for objects that haven't been specified, use 'nil', which is distinct from an NSNumber with 0 as a value.
You don't need to @retain BOOL or other primitive types in Objective-C - you only need use that for object types.
Upvotes: 0
Reputation: 22405
You dont need to have this BOOLean value to see if it is filled, why not just use the object itself to see if it has been initialized so something like
if(name==nil)
//this means i t hasnt been initialized
else
//this means it has
Upvotes: 2