Reputation: 139
I have two methods in my .m file .And i want to access by different values but in my Facebook variable gives nil value but if i use only one line and remove second line of object for key then it work fine for one method . How i do this which work for my both methods
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];
user=[defaults objectForKey:@"userid"];
facebook=[defaults objectForKey:@"FACEBOOKprofile"];
facebook =[defaults objectForKey:@"VLCC"];
if ([facebook isEqualToString:@"VLCCFACEBOOK"])
{
[self FacebookRecord];
}
else if([facebook isEqualToString:@"VLCC"])
{
[self VlccRecord];
}
Upvotes: 0
Views: 48
Reputation: 24248
int a = 10;
a = 20;
print >> a; //20
int a = 10;
print1 >> a; //10
a = 20;
print2 >> a; //20
Here,
a = facebook;
print1 = [self FacebookRecord];
print2 = [self VlccRecord];
I believe you'll understand.
Upvotes: 0
Reputation: 82766
assume that
Choice-1
// for accessing the both condition in same time
Initially Store the UserDefault value based
on your method.
if you are access with facebook
, on that time store the string like
[[NSUserDefaults standardUserDefaults] setObject:"VLCCFACEBOOK" forKey:@"FACEBOOKprofile"];
[[NSUserDefaults standardUserDefaults] synchronize];
if you are access with VLCC
, on that time store the string like
[[NSUserDefaults standardUserDefaults] setObject:"VLCC" forKey:@"VLCCprofile"];
[[NSUserDefaults standardUserDefaults] synchronize];
and retrieve the both and check like
if ([[[NSUserDefaults standardUserDefaults]
objectForKey:@"FACEBOOKprofile"]isEqualToString:@"VLCCFACEBOOK"])
{
[self FacebookRecord];
}
if([[[NSUserDefaults standardUserDefaults]
objectForKey:@"VLCCprofile"] isEqualToString:@"VLCC"])
{
[self VlccRecord];
}
Choice-2
// for accessing single condition on single time
if you are access with facebook
, on that time store the string like
[[NSUserDefaults standardUserDefaults] setObject:"VLCCFACEBOOK" forKey:@"FACEBOOKprofile"];
[[NSUserDefaults standardUserDefaults] synchronize];
if you are access with VLCC
, on that time store the string like
[[NSUserDefaults standardUserDefaults] setObject:"VLCC" forKey:@"FACEBOOKprofile"];
[[NSUserDefaults standardUserDefaults] synchronize];
and retrieve the both and check like
if ([[[NSUserDefaults standardUserDefaults]
objectForKey:@"FACEBOOKprofile"]isEqualToString:@"VLCCFACEBOOK"])
{
[self FacebookRecord];
}
else if([[[NSUserDefaults standardUserDefaults]
objectForKey:@"FACEBOOKprofile"] isEqualToString:@"VLCC"])
{
[self VlccRecord];
}
Upvotes: 1
Reputation: 1099
In your code, the [self VlccRecord]
method will always get called because you are overwriting the facebook variable.
facebook=[defaults objectForKey:@"FACEBOOKprofile"];
facebook =[defaults objectForKey:@"VLCC"];
If you are looking to append the two strings : Then use the stringbyAppendingString method.
Upvotes: 0