seeing if an object exists at index[i] in NSMUtableArray

Discussion in 'iOS Programming' started by ulquiorra, Sep 15, 2009.

  1. ulquiorra macrumors member

    Joined:
    Jun 17, 2009
    #1
    People I'd like to see if an element at index is not present in a different (or current ) array. So for instance if my array looked somewhat like this

    Code:
    [wer, wer4 , wer5 , werp , klo ...
    
    Then I would like to see if aExerciseRef.IDE ( which is "sdf" for instance ) does or does not exist at index. I assume I'd have to use some sort of iterator ..

    Code:
    for( int i = 0; i < 20; i++ )
    {
       if([instruct objectAtIndex:index2 + i] != [instruct containsObject:aExerciseRef.IDE] )                                       
       NSLog(@"object doesn't exist at this index %i, i );
       else
       NSLog(@"well does exist")
    }
    

    I know this doesn't work , it's just to elaborate what I'd like to achieve.

    edit:


    Let me elaborate a bit more
    I'm (again ) using XML parser for this one;).

    @HarryPotter thanks for your answer but that's not what I want to achieve.

    @dejo aExerciseRef is a class I'm using to fill different attributes ( just like the Books class in the this example http://www.iphonesdkarticles.com/2008/11/parsing-xml-files.html )

    example
    Code:
    
    		if( aworkout != nil )
    		{
    		aExerciseRef = [[exerciseref alloc] init];
    		aExerciseRef.IDE = [attributeDict objectForKey:@"id"];
    		aExerciseRef.header = [attributeDict objectForKey:@"header"];
    
    To elaborate a little further

    Imagine an array being filled with aExerciseRef.IDE's then I would like to compare if the elements in this array exist in the instruct array.

    So I would like to see if the element at let's say position 2 (wtrk).
    Code:
    [wer, wtrk, wer , sla ...
    
    exists in the array which was being filled with the aExerciseRef.IDE's.

    note: I'm using the same array here so not a different one that I'm filling. So i'm actually comparing if AN aExerciseRef.IDE is present at location index.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    First, what are the datatypes of aExerciseRef and aExerciseRef.IDE?
     
  3. HairyPotter macrumors regular

    Joined:
    Jul 4, 2007
    #3
    no, you use

    Code:
    [B]if ([yourArray containsObject:myObject])
    [/B]  yes, the array contains the object
    else
      no... the object is not on the array...
     
  4. ulquiorra thread starter macrumors member

    Joined:
    Jun 17, 2009
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Next time just add a new post, if there already are reply posts.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6

    So you have two arrays and you want to see if the objectAtIndex:i from the first array exists (somewhere) in the second array? Is that correct?
     
  7. ulquiorra thread starter macrumors member

    Joined:
    Jun 17, 2009
    #7
    yes dejo that's correct.

    And what I did was create something like this

    Code:
    for( int i = 1; i <= 5; i++ )
    	{
    		for( int j = 0; j < [aExerciseRefarray count]; j++ )
    			{
    			if([instruct objectAtIndex:index2 + i] != [aExerciseRefarray objectAtIndex:j]){
    			...									
    
    with the aExerciseRefArray filled with aExerciseRef.IDE's.

    However this doesn't seem to work.
     

Share This Page