0

これは私のコードです:

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
        }
    }
}

NSLog("count %d",count);情報なしでアプリをクラッシュさせようとすると。I'm sure that some times the condition return true... という別の問題もありif([source isEqualToString:element.source])ます...どうすれば空白を削除できますか? php のトリム関数のように?ありがとう

4

2 に答える 2

1

最初の 2 つの NSLog ステートメントに気付きませんでした。どちらも の形式NSLog("something: %@", something)です。これは C 文字列リテラルですが、NSLog はその形式に NSString を取ります。これはクラッシュにつながります。あなたがしたいNSLog(@"source: %@", source)

于 2011-09-02T23:29:14.467 に答える
1

変化する:

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

に:

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

空白を削除するには、次を試してください。

NSString *trimmedString = [yourString stringByReplacingOccurrencesOfString:@" " withString:@""];
于 2011-09-02T23:34:08.373 に答える