NSDictionary doesn't work

Joined
Mar 22, 2015
Messages
3
Reaction score
0
Points
1
Code:
[[NSBundle mainBundle] infoDictionary];
    NSString *cv = [[NSBundle mainBundle] pathForResource:@"Pezani Settings" ofType:@"plist"];
    NSDictionary *infocv = [NSDictionary dictionaryWithContentsOfFile:cv];
    NSString *Downloadcv = [infocv objectForKey:@"Word"];
 
 
 
NSString *testWord = [NSString stringWithFormat:@"Test"];
   
    if ([testWord isEqualToString: Downloadcv]) {
       
    }
    else {
        [self performSelector:@selector(PezaniCheckInternet) withObject:@"" afterDelay:0.0];
       
    }
 
Last edited by a moderator:

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,791
Reaction score
2,136
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Can you explain what you are trying to do and why you think it isn't working? What do you have in the plist file?
 
OP
T
Joined
Mar 22, 2015
Messages
3
Reaction score
0
Points
1
In the plist file there is a string.

Even if the word in the plist file is the same as in the code ("Test"),
it will still do the action.

The code needs to check if the word is the same as in the plist file, if it isn't the same, it should do the action. But now it always does the action.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,791
Reaction score
2,136
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
So you want the empty IF block to run as opposed to the ELSE block?

Debug the application and ensure that downloadcv does indeed contain the string "Test". You can very easily trace this code in XCode to see whats going on. With the debugger running you'll quickly see the problem..
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
If your Downloadcv variable is equal to nil, then your code is working correctly.
As the if condition has not been met.

If your expecting your Downloadcv variable to be something other than nil, then check the key exists in the Dictionary.

Regards Mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top