Install @property of Singleton class

I am currently using a property in the AppDelegate class.

Now that my needs are being spent, I need more than one of these global properties, so I decided to create a Singleton class that will hold properties and interfere with them. I found a lot of information about Singletons, but I could not figure out if it is possible to change a property without an instance of the class?

For instance:

@interface Tools : NSObject

@property (nonatomic,retain) NSDictionary* item;

... 

@end

I'd like to do:

[Tools setItem:someDict];
someClass = [someClass alloc] initWithItem:[Tools getItem]];

All my ideas ended up with the Tools class not having an instance. I tried to set the element as a static variable (not a property) that worked, but I'm sure this is not correct, why do this.

a related but different question, addition:

#import "Tools.h"

In the project-Prefix.pch file, so that the properties of the element will be available everywhere, in the project, is this a good idea?

+5
3

, singleton. ?

[Tools sharedInstance].item = someDict; // or
[[Tools sharedInstance] setItem:someDict;

sharedInstance . . . :

BOOL reset init

+5

Objective-C, , @property, . Objective-C

+2

There is a discussion of the @properties class in this ARC-related thread (the recommended way to do single-player games with ARC is class methods). Class variables do not exist yet, but I suggest you submit a radar to vote for this function.

0
source

All Articles