Skip to content

Instantly share code, notes, and snippets.

@petermolnar-dev
Last active November 9, 2016 20:36
Show Gist options
  • Save petermolnar-dev/14bd4dd1997b608e3b9dbc6bb835349a to your computer and use it in GitHub Desktop.
Save petermolnar-dev/14bd4dd1997b608e3b9dbc6bb835349a to your computer and use it in GitHub Desktop.
PMOPictureController.m
#import "PMOPictureController.h"
#import "PMODownloader.h"
#import "PMOPictureWithURL.h"
//1
#define CLASS_NAME NSStringFromClass([self class])
#define INIT_EXCEPTION_MESSAGE [NSString stringWithFormat:@"Use [[%@ alloc] initWithPictureURL:]",CLASS_NAME]
@interface PMOPictureController()
//2
/**
Our private data class, storing and hiding the information.
*/
@property (strong, nonatomic, nullable) PMOPictureWithURL *pictureWithUrl;
@end
@implementation PMOPictureController
#pragma mark - Initializers
- (instancetype)initWithPictureURL:(NSURL *)url {
if (url) {
self = [super init];
if (self) {
_pictureWithUrl = [[PMOPictureWithURL alloc] initWithPictureURL:url];
}
return self;
} else {
@throw [NSException exceptionWithName:@"Can't be initialised with null parameter"
reason:INIT_EXCEPTION_MESSAGE
userInfo:nil];
return nil;
}
}
//Save the diagnostic state
#pragma clang diagnostic push
//Ignore -Wobjc-designated-initializers warnings
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype)init
{
@throw [NSException exceptionWithName:@"Not designated initializer"
reason:INIT_EXCEPTION_MESSAGE
userInfo:nil];
return nil;
}
//Restore the disgnostic state
#pragma clang diagnostic pop
#pragma mark - Public API
- (void)downloadImage {
PMODownloader *downloader = [[PMODownloader alloc] init];
self.pictureWithUrl.image = [[UIImage alloc] initWithData:[downloader downloadDataFromURL:self.pictureWithUrl.imageURL]];
}
- (UIImage *)image {
return self.pictureWithUrl.image;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment