Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1054665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:26:30+00:00 2026-05-16T17:26:30+00:00

I keep getting the error Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘+[MainViewController

  • 0

I keep getting the error “Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘+[MainViewController minimalFormInContext:]: unrecognized selector sent to class”
from this line of code:
NSLog(@”Accessing specific mine entities”);

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Mine" inManagedObjectContext:managedObjectContext];   
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];   
NSError *error = nil;
[request setEntity:entity];  
NSPredicate *predicate;
NSPredicate *metalFilter;

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *region = [defaults stringForKey:@"mineArray"];

if([region isEqualToString:@"Butte & Plumas"])
{
    predicate = [NSPredicate predicateWithFormat:@"(county Contains %@)  OR (county Contains %@)",@"Butte",@"Plumas"];
}
else if([region isEqualToString:@"Sutter, Yuba, & Sierra"])
{
    predicate = [NSPredicate predicateWithFormat:@"(county Contains %@)  OR (county Contains %@) OR (county Contains %@)",@"Sutter",@"Yuba",@"Sierra"];
}
else if([region isEqualToString:@"Nevada & Placer"])
{
    predicate = [NSPredicate predicateWithFormat:@"(county Contains %@)  OR (county Contains %@)",@"Nevada",@"Placer"];
}
else if([region isEqualToString:@"Sacramento & El Dorado"])
{
    predicate = [NSPredicate predicateWithFormat:@"(county Contains %@)  OR (county Contains %@)",@"Sacramento",@"El Dorado"];
}
else if([region isEqualToString:@"San Joaquin, Amador, & Calaveras"])
{
    predicate = [NSPredicate predicateWithFormat:@"(county Contains %@)  OR (county Contains %@) OR (county Contains%@)",@"San Joaquin",@"Amador", @"Calaveras"];
}
else if([region isEqualToString:@"Tuolumne & Stanislaus"])
{
    predicate = [NSPredicate predicateWithFormat:@"(county Contains %@)  OR (county Contains %@)",@"Tuolumne",@"Stanislaus"];
}
else if([region isEqualToString:@"Merced, Mariposa, & Madera"])
{
    predicate = [NSPredicate predicateWithFormat:@"(county Contains %@) OR (county Contains %@) OR (county Contains %@)",@"Merced",@"Mariposa",@"Madera"];
}

[request setPredicate:predicate];
mArray = [[NSMutableArray alloc] init];
mArray = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];

using debugger, I have narrowed down the error as occurring in:

mArray = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];

How do I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:26:30+00:00Added an answer on May 16, 2026 at 5:26 pm

    It’s likely that it’s a retain/release bug. Do “Build and Analyze” in XCode, and improve your code to remove all of the warnings.

    Here are things I noticed:

    mArray = [[NSMutableArray alloc] init];
    mArray = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
    

    These two lines are very bad. What’s your mArray? Does m stands for member, or mutable? If it’s a member variable, you shouldn’t just assign a new array to that as in

    // mArray points to an array at this time, say X
    mArray = [[NSMutableArray alloc] init];
    // at this point, mArray points to an array Y created by alloc init. X is lost! 
    

    Moreover, if you further assign a mutableCopy as you did,

    mArray = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
    // at this point, mArray points to an array Z created by mutableCopy. Y is lost, too!
    

    Note that in Objective-C, the variables you see on the source code is just a pointer, not the object itself. If you assign something to a variable, it doesn’t make the object perform the assign operation, but it just changes the pointer to point to something different.

    The fact that you have these lines suggests you have similar things in various other places; any of it can eventually lead to the bug you’re encountering. So you need to deal with them one by one. Good luck!

    Another point: when you prepare the variable predicate, the chain of if clauses leaves predicate undefined if region matches none of the choices you listed. This is very dangerous, because in Objective-C, the line

     NSPredicate* predicate;
    

    does not initialize predicate to be nil. So it’s possible that

    [request setPredicate:predicate];
    

    will set a garbage to the predicate of requrest. You should change it to

     NSPredicate* predicate=nil;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting the following error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
I published app at the Market and I keep getting error: Exception class: android.content.res.Resources$NotFoundException
I keep getting this error with my Play 2.0 application: play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[MatchError:
For some reason I keep getting error C3861: '__typeof': identifier not found when I
I'm trying to install a package that uses global-linum-mode and keep getting: error Autoloading
With the following code, I keep getting error C2535 when I compile. It's complaining
I'm trying to code some stuff for a game but I keep getting error
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.