0

This is my code:

for (int i=0; i<countingArray.count; i++) {
    NSDictionary *element=[countingArray objectAtIndex:i];
    NSString *source=[element objectForKey:@"id"];
    NSInteger count= [[element objectForKey:@"count"] integerValue];
    NSLog("source: %@",source); //Works
    NSLog("count %d",count);    //Don't Work! Error at this line

    for(int c=0; c<subscriptions.count; c++) {
        SubscriptionArray * element =[subscriptions objectAtIndex:c];
        NSLog(@"sorgente sub %@",element.source);
        NSLog(@"sorgente counting %@",source);
        if([source isEqualToString:element.source]) {
            element.count=count;
            [subscriptions replaceObjectAtIndex:c withObject:element];
            NSLog(@"equal"); 
            //this part of code is never been executed but I'm sure that
            //the if condition in some cases returns true
        }
    }
}

When I try to NSLog("count %d",count); my app crash without any information about. I've also another problem with if([source isEqualToString:element.source]) I'm sure that some times the condition return true... How can I remove blank space? Like the trim function in php? thanks

paul_1991
  • 231
  • 1
  • 7
  • 16

2 Answers2

1

I didn't notice the first two NSLog statements. They're both of the form NSLog("something: %@", something). That is a C string literal, whereas NSLog takes an NSString for its format. This will lead to a crash. You want NSLog(@"source: %@", source).

Chuck
  • 234,037
  • 30
  • 302
  • 389
1

Change:

NSString *source=[element objectForKey:@"id"];
NSInteger count= [[element objectForKey:@"count"] integerValue];

to:

 NSString *source=[element valueForKey:@"id"];
 NSInteger count= [[element valueForKey:@"count"] integerValue];

For removing blank spaces you can try:

NSString *trimmedString = [yourString stringByReplacingOccurrencesOfString:@" " withString:@""];
Sid
  • 9,508
  • 5
  • 39
  • 60