1

I am trying to pass an NSArray to a NSMutableArray but am having a few issues doing so and was hoping someone could help.

- (void)CachedData:(NSArray *)gArray indexPath:(NSIndexPath *)gIndex dataSetToParse:(NSString *)string
{
    //Set dataSetToParse so the parsing delegates if statment works correctly
    dataSetToParse = string;

    //Calls method that sets the accessory tick
    [self setAccessoryIndexPath:gIndex];

    //Set array that can be used in this view
    [parsedDataArray addObjectsFromArray:gArray];


    //Use this method to pass NSData object to startTheParsingProcess method and also to initalize indexPathVariable
    [self startSortingTheArray:gArray];
}

When I try to log parsedDataArray after I addObjects to it all I get is

(null) (null) .... etc.

any help would be appreciated.

Update The main issue here is that I have 4 lots of arrays. with 3 views, a main view sub view and then a sub subview. each array has a refrence ID to the next array, I want to parse each array before I display them to check if there are any values in them based off the restriction string. If there are no values then I will either send the user back to the main view or just not allow them to select the cell that has an array with no related values. (I hope you get what I am doing here)

The solution I have come up with for that is to parsed the values in the parent view of where I intend to display them...

if you look at my views

view 1
- view 2
-- view 3

I need a parsing delegate for view 1 and 2, because I need to check the values of view 3 in view 2.. However this is causing me an issue because I am using the same array to avid redundancy to return the value to the main view and create/check the values of the subview.

So I am trying to skip over the parser delegates of view 2 if i am not going to display anything in view 3, by passing my already parsed array into the mutablearray I will pass the data back with inside didselectcell method...

Anyway I hope this makes sense.. its the only way I think I can do this.. if you know better please let me know your strategy.

5
  • 2
    Seems like you try to added the same array... [parsedDataArray addObjectsFromArray:parsedDataArray]; Commented Jan 23, 2012 at 21:39
  • 1
    You're adding your array's elements to the original array itself...!? Commented Jan 23, 2012 at 21:39
  • [parsedDataArray addObjectsFromArray:parsedDataArray]; looks strange: You're adding elements from an array to itself? Commented Jan 23, 2012 at 21:39
  • opps i was adding it in because I had deleted it and tried something else.. looks like I had a bran freeze! the code is updated now. Commented Jan 23, 2012 at 21:41
  • @H2CO# yes I am I have done an nslog on the on the gArray and it prints the correct data to the log. Commented Jan 23, 2012 at 21:49

3 Answers 3

4

Assuming the parsedDataArray is a mutable array declared somewhere else, this wouldn't make sense:

//Set array that can be used in this view
[parsedDataArray addObjectsFromArray:parsedDataArray];

Unless you mean to double all of the objects in the parsedDataArray. I think what you meant is:

//Set array that can be used in this view
[parsedDataArray addObjectsFromArray:gArray];

But I can't be sure without more context or explanation.

Sign up to request clarification or add additional context in comments.

3 Comments

yep its ment to be gArray.. what is happening is I have several arrays which I display and select values from in a subview.. However I am parsing some of those arrays in the mainview because I need to know if there are any related ID's to previously selected values if not then I don't let them choose the next cell which would generate the next array of items to choose from in the subview because there are no items... However the consequence of that is I am having to skip the parsing method in the subview..
don't add the elements then, just set the array: [mutableArray setArray:otherArray];
okay I will try now, I just tried it and I put a NSLog before I setArray with gArray as the print out then after setarray of the parsedDataArray and i get the whole array printed out followed by the (null)... so painfull... im thinking maybe its not allocated yet?
2

check if garray is containing the data or not, by printing it in nslog

also check if u have intialized parsedDataArray as below or not parsedDataArray=[[NSMutableArray alloc]init]; in Viewdidload delegate

Comments

2
NSArray *array = [NSArray arrayWithObjects:@"Raja",@"Ram",nil];

NSMutableArray *muArray = [NSMutableArray arrayWithArray:array];

1 Comment

this should be arrayWithArray, not arrayWitharray

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.