• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CoreData headaches
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData headaches


  • Subject: Re: CoreData headaches
  • From: Steve Mills <email@hidden>
  • Date: Fri, 28 Oct 2016 23:44:27 -0500

On Oct 27, 2016, at 23:35:39, Dave Fernandes <email@hidden> wrote:
>
> The managed objects exist in a MOC whether you have a reference to that MOC or not. You can get a reference to the MOC that an MO “belongs to" from the -[NSManagedObject managedObjectContext] instance method. Since the properties you need are so few and simple, why don’t you just pass these in to the NSOperation when you create it on the main thread instead of giving it the managed object? Then the MO will never be accessed off the main queue.

I moved the CGImageSource creation to outside the block, which is where I needed to access the managed object's folder and name properties. The block now just loads the image from the source, converts it to an NSImage, and sets the managed object's thumb property. It's no longer crashing, but the setting of the thumb property seems like that shouldn't happen inside the block. So would that be the right place to use the NSManagedObjectContext's performBlock:? Here's the managed object's method:

-(void) requestPreviewImageAtSize:(CGFloat)size
{
    if(_thumbOp)
        [_thumbOp cancel];

    if([self createImageSource]) {
        _thumbOp = [NSBlockOperation blockOperationWithBlock:^{
            if(_thumbOp.isCancelled)
                return;

            NSDictionary*            opts = @{(__bridge NSString*)kCGImageSourceCreateThumbnailFromImageAlways:@YES, (__bridge NSString*)kCGImageSourceThumbnailMaxPixelSize:@(size)};
            CGImageRef               thumbnail = CGImageSourceCreateThumbnailAtIndex(_imageSource, 0, (__bridge CFDictionaryRef)opts);

            if(thumbnail) {
                if(!_thumbOp.isCancelled) {
                    NSImage*            image = [[NSImage alloc] initWithCGImage:thumbnail size:NSZeroSize];

                    if(image && !_thumbOp.isCancelled) {
                        [self.managedObjectContext performBlock:^{
                            self.thumb = image;
                        }];
                    }
                }

                CGImageRelease(thumbnail);
            }
        }];

        [_thumbOp setCompletionBlock:^{
            _thumbOp = nil;
        }];

        [[[self class] previewLoadingOperationQueue] addOperation:_thumbOp];
    }
}

--
Steve Mills
Drummer, Mac geek


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: CoreData headaches
      • From: Chris Hanson <email@hidden>
References: 
 >CoreData headaches (From: Steve Mills <email@hidden>)
 >Re: CoreData headaches (From: Dave Fernandes <email@hidden>)
 >Re: CoreData headaches (From: Steve Mills <email@hidden>)
 >Re: CoreData headaches (From: Dave Fernandes <email@hidden>)
 >Re: CoreData headaches (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: CoreData headaches
  • Next by Date: Prioritizing drawing of the important stuff
  • Previous by thread: Re: CoreData headaches
  • Next by thread: Re: CoreData headaches
  • Index(es):
    • Date
    • Thread