开发者

replaceObjectAtIndex:i withObject:str is giving bad access error (also with remove object - even do i can addObject atIndex

开发者 https://www.devze.com 2023-02-11 18:08 出处:网络
I\'m trying to replace a string in an array(update array) with a string found at an index of array(other array). Both arrays are initialized in init and i can nslog them in this method. if [str isEqua

I'm trying to replace a string in an array(update array) with a string found at an index of array(other array). Both arrays are initialized in init and i can nslog them in this method. if [str isEqualToString:[otherArray objectAtIndex:i] i want to return true/YES

but the line: [updateArray replaceObjectAtIndex:i withObject:str]; is giving bad access to program. (its only a console program) "Program received signal: “EXC_BAD_ACCESS”.

any suggestions appreciated, thanks trev

-(BOOL)checker:(NSString *)str {

    NSLog(@"update arrayobject at %d is %@",0, [updateArray objectAtIndex:0]);  


    NSLog(@"otherArray size is %d",[otherArray count]);
    NSLog(@"str iput is %@",str);
    int i;
    for (i=0; i<[otherArray count]; i++) {
        if ([str isEqualToString:[otherArray objectAtIndex:i]]) {
            [updateArray replaceObjectAtIndex:i withObject:str];
        return TRUE;
        }

 开发者_JS百科   }   
        return FALSE;
}


once check your array is it allocated or not properly..i think there is nothing more than that thing..

0

精彩评论

暂无评论...
验证码 换一张
取 消