0

I have NSMutableArray like following:

In .h

@property (nonatomic,retain) NSMutableArray *arrReceipes; 

In .m

@synthesize arrReceipe;   

Inside a method

arrReceipes = [[NSMutableArray alloc] init];    
NSArray *arrReceipesTime1;    
NSArray *arrReciepHeart;     
NSArray *arrRecipeLifestyle;     

arrReceipesTime1 = [NSArray arrayWithObjects:@"Half an hour or less",@"About an     hour",@"More than an hour", nil];     

NSDictionary *arrReceipeTime1Dict = [NSDictionary dictionaryWithObject:arrReceipesTime1 forKey:@"Find Recipes"];    

arrReciepHeart = [NSArray arrayWithObjects:@"HealthyAndDelicius", nil];    
NSDictionary *arrRecipesHeartDict = [NSDictionary dictionaryWithObject:arrReciepHeart   forKey:@"Find Recipes"];     

arrRecipeLifestyle = [NSArray arrayWithObjects:@"Recipe for fall",@"Quick and   easy",@"Cooking for kids",@"Easy entertaining",@"American classics",@"Outdoor cooking",   nil];     
NSDictionary *arrRecipeLifestyleDict = [NSDictionary dictionaryWithObject:arrRecipeLifestyle forKey:@"Find Recipes"];     

[arrReceipes addObject:arrReceipeTime1Dict];
[arrReceipes addObject:arrRecipesHeartDict];
[arrReceipes addObject:arrRecipeLifestyleDict];

That is "arrReceipes" is my NSMutable array.

Now I want to extract the value/string of "arrReceipes" and put it into "NSArray * somevariable".

How can I do this?

This I' doing for :

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
       NSIndexPath *indexPath = [self.tableView1 indexPathForSelectedRow];
       RecipeDetailViewController *destViewController = segue.destinationViewController;

       destViewController.recipeName = [arrReceipes objectAtIndex:indexPath.row];
    }
}

In my 3rd line above(in 'if') if I'm giving "arrReceipes" its throwing exception in "main" method.But, if, instade of giving "arrReceipes" I'll give "somevariable" its working fine.

Hope you understand my problem.Please help.Thanks.

1
  • What exception is it throwing, and on what line? Commented Dec 5, 2012 at 18:31

3 Answers 3

1

The objects that you're putting into arrReceipes are dictionaries, so the destViewController.recipeName should be a dictionary if you want to pass it one of those objects.

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

4 Comments

Hi Phillip, Could you please more elaborate.Give some example code.Thanks.
What part of "destViewController.recipeName should be a dictionary" don't you understand?
Or, (probably more likely) he needs to extract the recipe name from the dictionary and set the variable in the new view controller.
Certainly deciding what data type is to be passed would be a good step.
0

You can't write in an NSArray.

However you can do something like this:

NSArray * somevariable = [arrReceipes copy];

Also you can modify your code to write the data into a NSMutableArray and then copy it to arrRecipes

4 Comments

give full answer, he cant use copy (ARC will create issue)
Why would copy give problems in ARC. I've just copy just fine in a project with ARC.
I tryed doing:NSArray * somevariable = [arrReceipes copy]; But, this does not help.Its showing same exception.Any other solution??
@Jyotiranjan - I've checked the iOS documentation again, and I still can't find a "same" exception.
0

You can try with

NSArray *somevariable = [NSArray arrayWithArray:arrReceipes];

NSMutableArray is a subclass of an NSArray so you can just use NSArray methods

Comments

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.