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

  • Home
  • SEARCH
  • 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 6230011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:40:15+00:00 2026-05-24T09:40:15+00:00

This has been bugging me for 2 days now and I cant get my

  • 0

This has been bugging me for 2 days now and I cant get my head around it. I want to extract several images that are stored in my core data store. The images are user selected using the image picker and rendered to a size of less then 70KB, transformed to data and popped into the core data store. The images are to be used in a slideshow. Entity is called ImageCD and the image is stored in the attribute friendsPhoto. I also allocate a date attribute to sort the images. This is done when the image is saved and is also an attribute of ImageCD.

I am using the following code to TRY and set the array but it does not return anything. im not getting a (NULL) readout on the debugger just that “Number of elements in array = 0;”

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
NSLog(@"array's content sortDe:%@",sortDescriptors);

NSMutableArray* sortedImages = [[NSMutableArray alloc] initWithObjects:imageCD.friendsPhoto, nil];
[sortedImages sortUsingDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release]; 
NSLog(@"array's content:%@",sortedImages);


imageArray = [[NSMutableArray alloc]init] ;
self.imageArray = sortedImages;
NSLog (@"Number of elements in array = %i", [imageArray count]);


self.theImageView.animationImages = [[NSArray alloc] initWithArray:imageArray];
NSLog(@"animationImages:%@",self.theImageView.animationImages);

So, what am I doing wrong? I have my suspicions it is something to do with this line of code…

NSMutableArray* sortedImages = [[NSMutableArray alloc] initWithObjects:imageCD.friendsPhoto, nil];

But cant work out what the alternate should be. I will be forever indebted to whoever can correct my mistake. I thank you in advance and please, let me know if you require any further information, a beer or a bacon sandwich.

Ohh, to save my sanity, I sanity checked the images by adding a class from my previous app (My Outfit) which utilizes this approach to retrieving images from core data BUT within a tableView, so called in cellForRowInIndexPath etc. and all the images are sound.

DetartrateD

 2011-08-04 19:40:33.051 My Class Book[1027:707] After managedObjectContext:         <NSManagedObjectContext: 0x1821b0>
2011-08-04 19:40:33.057 My Class Book[1027:707] array's content sortDe:(
"(date, ascending, compare:)"
   )
  2011-08-04 19:40:33.059 My Class Book[1027:707] array's content:(
)
2011-08-04 19:40:33.061 My Class Book[1027:707] Number of elements in array = 0
2011-08-04 19:40:33.063 My Class Book[1027:707] animationImages:(
)

Now fixed with these changes
…

NSMutableArray *mutableFetchResultsA = [[managedObjectContext  executeFetchRequest:requestA error:&error] mutableCopy];
if (mutableFetchResultsA == nil) {
    NSLog(@"Testing: No results found");

}
else {

    NSLog(@"Testing: %d Results found.", [mutableFetchResultsA count]);
    NSLog(@"array's content sortDe:%@",mutableFetchResultsA);
}   
[sortDescriptor release];
[sortDescriptors release]; 


imageArray = [[NSMutableArray alloc]init] ;
self.imageArray = [mutableFetchResultsA valueForKey:@"friendsPhoto"];

[mutableFetchResultsA release];
[requestA release];

…

  • 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-24T09:40:16+00:00Added an answer on May 24, 2026 at 9:40 am

    Assuming that the images are stored as NSData * attributes in the ImageCD entity, here is what you need to do:

    self.imageArray = [self getImagesInManagedObjectContext:self.managedObjectContext];
    

    Here is the getImagesInManagedObjectContext: method. This method retrieves from the Core Data store the ImageCD objects, sorted using your attribute as required, then creates and returns an autoreleased NSMutableArray of UIImage * objects or nil if no objects have been found.

    - (NSMutableArray *) getImagesInManagedObjectContext:(NSManagedObjectContext *)moc{
        NSFetchRequest *request = [[NSFetchRequest alloc] init];
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"ImageCD" inManagedObjectContext:moc];
        [request setEntity:entity];
    
        // Edit the sort key as appropriate.
        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
        [request setSortDescriptors:sortDescriptors];
    
        NSError *error = nil;
        NSMutableArray *array = [NSMutableArray arrayWithArray: [moc executeFetchRequest:request error:&error]];
        [request release];
        [sortDescriptor release];
        [sortDescriptors release];
        if (array && [array count] && !error){
                    // create an array of images
                    NSMutableArray *images = [[NSMutableArray alloc] init];
                    for(ImageCD *obj in array){
                       UIImage *img = [UIImage imageWithData: (NSData *) obj.friendsPhoto];
                       [images addObject:img];
                    }
    
            return [images autorelease];
        }
        else
            return nil;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been bugging me for days, cant seem to get an answer after
This has been bugging me for more than two days now, so i thought
This has been bugging me for a couple days now. A list has content
This issue has been bugging me for the past several days. I've been working
Ok this is bizarre and has been bugging me for days now.... I did
This one has been bugging me for a while now. Is there a way
This Jquery problem has been bugging me for a while now. I developed a
This is a question that has been bugging me for a while. I started
This is a strange one that has been bugging me today. Due to the
This has been bugging me for a couple days. I'm trying to load a

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.