1

Maybe somebody will know, how to "tag" NSuserdefaults.

I have like 10 user defaults: name pin etc...

I want to make another object, which would have the same defaults as the other ones (same variables but different values). Like a version, if object == 1 then load one userdefaults and if object == 0 another ones. But how to make it done?

Tried to make something like this

[NSUserDefaults setVersion:object.intValue];

But i guess this isn't the way to do it. So maybe anyone could help how to make it done?

To be more specific a simple example would help like how to do this:

Object (1 or 0)

[[NSuserDefaults  standartUserDefaults] setObject: @"something"
                                                 forKey: @"Name"];
[[NSUserDefaults standartUserDefaults] synchronize];

NSString *name = [[NSUserDefaults standartUserDefaults] stringForKey:"@name"];

How to set and get this Name depending on Object value?

4

1 に答える 1

0

永続ドメインを使用できます。

NSMutableDictionary *defaults = [[[NSUserDefaults standardUserDefaults] persistantDomainForName:@"aString"] mutableCopy];

// make changes to the dictionary here

[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:@"aString"];
[[NSUserDefaults standardUserDefaults] setPersistantDomain:defaults forName:@"aString"];

これを行う場合、辞書を介してすべてのデフォルトにアクセスする必要があることに注意してください。

于 2012-11-13T09:10:52.963 に答える