Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move assertions so they are valid. #1261

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Source/Details/ASPINRemoteImageDownloader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ + (ASPINRemoteImageDownloader *)sharedDownloader NS_RETURNS_RETAINED

+ (void)setSharedImageManagerWithConfiguration:(nullable NSURLSessionConfiguration *)configuration
{
NSAssert(sharedDownloader == nil, @"Singleton has been created and session can no longer be configured.");
PINRemoteImageManager *sharedManager = [self PINRemoteImageManagerWithConfiguration:configuration imageCache:nil];
[self setSharedPreconfiguredRemoteImageManager:sharedManager];
}

+ (void)setSharedImageManagerWithConfiguration:(nullable NSURLSessionConfiguration *)configuration
imageCache:(nullable id<PINRemoteImageCaching>)imageCache
{
NSAssert(sharedDownloader == nil, @"Singleton has been created and session can no longer be configured.");
PINRemoteImageManager *sharedManager = [self PINRemoteImageManagerWithConfiguration:configuration imageCache:imageCache];
[self setSharedPreconfiguredRemoteImageManager:sharedManager];
}
Expand All @@ -131,7 +133,6 @@ + (void)setSharedImageManagerWithConfiguration:(nullable NSURLSessionConfigurati
+ (void)setSharedPreconfiguredRemoteImageManager:(PINRemoteImageManager *)preconfiguredPINRemoteImageManager
{
NSAssert(preconfiguredPINRemoteImageManager != nil, @"setSharedPreconfiguredRemoteImageManager requires a non-nil parameter");
NSAssert(sharedDownloader == nil, @"Singleton has been created and session can no longer be configured.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But removing it here means I can get away with calling this method directly, even after a singleton was created? Having said that, I don't care that much tbh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true (if you managed to create a sharedDownloader but without a sharedPINRemoteImageManager, which will assert below) you could make your way through here and miss the asserts. It's definitely wrong as-is though.

NSAssert1(sharedPINRemoteImageManager == nil, @"An instance of %@ has been set. Either configuration or preconfigured image manager can be set at a time and only once.", [[sharedPINRemoteImageManager class] description]);

dispatch_once(&shared_init_predicate, ^{
Expand Down