Upvote:1

Aprove answer
[library assetForURL:[NSURL URLWithString:student.portrait.assetURL] resultBlock:^(ALAsset *asset) {...

Upvote:2

cell.nameFirst.text = student.nameFirst;
cell.nameLast.text = student.portrait.assetURL;

// Portrait
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library assetForURL:[NSURL URLWithString:student.portrait.assetURL] resultBlock:^(ALAsset *asset) {
    ALAssetRepresentation *representation = [asset defaultRepresentation];
    CGImageRef assetRef = [representation fullResolutionImage];
    if (assetRef) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [cell.portrait setImage:[UIImage imageWithCGImage:assetRef]];
        });
    }
} failureBlock:^(NSError *error) {}];

return cell;

More Answer related to the Same Query

Upvote:1

@interface SimpleImageCache ()

@property (nonatomic, strong) NSMutableDictionary* images;
@property (nonatomic, strong) ALAssetsLibrary* assetsLibrary;
@property (nonatomic, strong) UIImage* missingImage;
@end

@implementation SimpleImageCache {
    dispatch_queue_t _sync_queue;
}

- (id)init {
    self = [super init];
    if (self) {
        _sync_queue = dispatch_queue_create("sync_queue", NULL);
    }
    return self;
}

- (NSMutableDictionary*) images {
    if (_images == nil) {
        _images = [[NSMutableDictionary alloc] init];
    }
    return _images;
}

- (ALAssetsLibrary*) assetsLibrary {
    if (_assetsLibrary == nil) {
        _assetsLibrary = [[ALAssetsLibrary alloc] init];
    }
    return _assetsLibrary;
}

- (UIImage*) imageWithURL:(NSURL*)url {
    __block UIImage* image;
    dispatch_sync(_sync_queue, ^{
        id obj = self.images[url];
        if ([obj isKindOfClass:[UIImage class]]) {
            image = obj;
        }
    });
    return image;
}

- (void) loadImageWithURL:(NSURL*)url completion:(completion_t)completionHandler {
    dispatch_async(_sync_queue, ^{
        if (self.images[url] != nil) {
            return;
        }
        self.images[url] = @"pending";
        [self.assetsLibrary assetForURL:url resultBlock:^(ALAsset *asset) {
            ALAssetRepresentation* representation = [asset defaultRepresentation];
            __block  UIImage* image = CFBridgingRelease([representation fullResolutionImage]);
            dispatch_async(_sync_queue, ^{
                if (image == NULL) {
                    image = self.missingImage;
                    NSAssert(image, @"image is nil");
                }
                self.images[url] = image;
                if (completionHandler) {
                    dispatch_async(dispatch_get_global_queue(0, 0), ^{
                        completionHandler(image, nil);
                    });
                }
            });
        } failureBlock:^(NSError *error) {
            if (completionHandler) {
                dispatch_async(dispatch_get_global_queue(0, 0), ^{
                    completionHandler(nil, error);
                });
            }
        }];
        
    });
}

@end

Credit Goes to: stackoverflow.com

Related question with same questions but different answers