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 1064751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:43:01+00:00 2026-05-16T19:43:01+00:00

I am getting a weird crash when I try to save my model. This

  • 0

I am getting a weird crash when I try to save my model. This is my code:

 TJModel *model = [TJModel sharedTJModel];
 NSFetchRequest *request = [[[NSFetchRequest alloc] init]autorelease];
 [request setReturnsObjectsAsFaults:NO];
 NSEntityDescription *entity = [NSEntityDescription entityForName:@"TJVideoList"inManagedObjectContext:[model managedObjectContext]];
 [request setEntity:entity];

 NSError *error = nil;
 NSMutableArray *mutableFetchResults = [[[model managedObjectContext] executeFetchRequest:request error:&error] mutableCopy];

if (error != nil)
  NSLog(@"error %@",[error localizedDescription]);


 TJVideoList *videoList = nil;

 if ([mutableFetchResults count] == 0) {

  videoList = (VideoList *)[NSEntityDescription insertNewObjectForEntityForName:@"TJVideoList" 
                 inManagedObjectContext:[model managedObjectContext]];
 }
 else 
 {
  videoList = [mutableFetchResults objectAtIndex:0];
 }


 [videoList addVideoListObject:recordedVideo];
 error = nil;

 if (![[model managedObjectContext] save:&error]) {

And crash …..This is what said in the terminal:

-[NSConcreteValue UTF8String]: unrecognized selector sent to instance 0x1d33f0

I thought it might be a cuestion of deallocated objects, so I retained them like this:

[managedObjectContext setRetainsRegisteredObjects:YES];

With no luck.

  • 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-16T19:43:01+00:00Added an answer on May 16, 2026 at 7:43 pm

    Your crash is not a result of this code.

    Crashes in saves usually result from an error with an managedObject’s attributes. In this case, you have somewhere assigned the wrong value to a string attribute. When the context goes to convert the string attribute to a UTF8 string for persistence, the object that is there instead of the NSString does not understand the message and the crash results.

    Although this code should run okay, you do have some risky practices:

    NSFetchRequest *request = [[[NSFetchRequest alloc] init]autorelease];
    

    This is a bad practice. autorelease is the same as release. You should not send it to an object until you are complete done with it. autorelease marks an object for death the next time the memory pool is drained. In some case, that will kill the object unexpectedly. While it won’t cause problems here, you don’t want to get into the habit of taking this short cut because it will eventually bite you.

    You should only use autorelease when the current scope is done with the object but the object is being sent outside the scope (usually in a method return.)

    NSMutableArray *mutableFetchResults = [[[model managedObjectContext] executeFetchRequest:request error:&error] mutableCopy];
    

    The mutable array here is pointless as is the copy. This is apparently in some reference material somewhere because it keeps cropping up novices code in the last few months. If you’re not going to alter an array there is no reason to have it mutable. In the case of an array of managed objects, it is pointless to copy the array.

    videoList = [mutableFetchResults objectAtIndex:0]
    

    Since you have no sort descriptor for the fetch, the mutableFetchResults array will be in a random order. If you have more than one object returned, which is almost always the case, you will get a random TJVideoList object at the zero element every time you run the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.