-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow configuring imageCache when initializing ASPINRemoteImageDownloader. #1197
Conversation
…n initializing ASPINRemoteImageDownloader.
@nguyenhuy @ernestmama @garrettmoon Could someone please take a look over this PR. Thanks! |
} else { | ||
PINRemoteImageManager *manager = nil; | ||
// Check that Carthage users have linked both PINRemoteImage & PINCache by testing for one file each | ||
if (!(NSClassFromString(@"PINRemoteImageManager"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put that behind a debug flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to put these checks behind the PIN_ANIMATED_AVAILABLE
flag, just like the previous implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered as I looked over it the first time why this was the case? cc @garrettmoon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I hit the error condition once, and didn't get the exception, and saw that, and thought it would be helpful, and it didn't have anything really to do with PIN_ANIMATED_AVAILABLE
specifically, so I moved it out. takes a breath
I can see putting it behind #if DEBUG
, although it's just going to crash either way and for a check that is guaranteed to only ever run once it doesn't seem like two NSClassFromString
s is that expensive. But it's of limited use without a debugger attached (you would get a friendlier crash report from Apple if your released app hit here, but then presumably your app is crashing every time so ...... you hopefully have it figured out)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course now that I've done it, it seems like it might as well be an assertion instead if it's only on DEBUG
.
I agree that I'm interested in Garret's take here as well.
} | ||
|
||
- (PINRemoteImageManager *)sharedPINRemoteImageManager | ||
{ | ||
return [ASPINRemoteImageDownloader sharedPINRemoteImageManagerWithConfiguration:nil preconfiguredPINRemoteImageManager:nil]; | ||
if (!sharedPINRemoteImageManager) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we have to have this check here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give me a minute to try to remember lol!
If I can't, I will write it off as a brain fart...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I took nine, and I got nothing! I am pretty sure I had worked myself into some overcomplicated concurrency scenario that cannot actually exist and wouldn't have been completely helped anyway
#else | ||
sharedPINRemoteImageManager = [[ASPINRemoteImageManager alloc] initWithSessionConfiguration:configuration]; | ||
manager = [[ASPINRemoteImageManager alloc] initWithSessionConfiguration:configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change to manager instead of sharedPINRemoteImageManager
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it's not shared - I funneled all the set-shared logic into as few places (two, unfortunately couldn't get it to one without changing the API of the getter) as possible to reduce complexity. This method just configures a manager and returns it to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change to manager instead of sharedPINRemoteImageManager?
This method is no longer a setter but a builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool than we should change the other sharedPINRemoteImageManager
to the manager
variable too :)
@@ -47,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN | |||
* | |||
* @param preconfiguredPINRemoteImageManager The preconfigured remote image manager that will be used by `sharedDownloader` | |||
*/ | |||
+ (void)setSharedPreconfiguredRemoteImageManager:(nullable PINRemoteImageManager *)preconfiguredPINRemoteImageManager; | |||
+ (void)setSharedPreconfiguredRemoteImageManager:(PINRemoteImageManager *)preconfiguredPINRemoteImageManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove the nullable here it does not match with the implementation. Any reason we removed it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should change the implementation if I didn't. It makes no sense to call this with nil
, to support it would be to add a check right away along the lines of if (preconfiguredPINRemoteImageManager == nil) return;
which is silly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing nullable
here is fine. It doesn't make sense to pass in a nil
manager here anyway, and it isn't obvious what the framework would do in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I did actually also change the implementation so I'm happy with this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the doc comments. The doc still say passing in a nil as the PINRemoteImageManager, it will create a default one.
@@ -47,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN | |||
* | |||
* @param preconfiguredPINRemoteImageManager The preconfigured remote image manager that will be used by `sharedDownloader` | |||
*/ | |||
+ (void)setSharedPreconfiguredRemoteImageManager:(nullable PINRemoteImageManager *)preconfiguredPINRemoteImageManager; | |||
+ (void)setSharedPreconfiguredRemoteImageManager:(PINRemoteImageManager *)preconfiguredPINRemoteImageManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing nullable
here is fine. It doesn't make sense to pass in a nil
manager here anyway, and it isn't obvious what the framework would do in that case.
} else { | ||
PINRemoteImageManager *manager = nil; | ||
// Check that Carthage users have linked both PINRemoteImage & PINCache by testing for one file each | ||
if (!(NSClassFromString(@"PINRemoteImageManager"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to put these checks behind the PIN_ANIMATED_AVAILABLE
flag, just like the previous implementation.
#else | ||
sharedPINRemoteImageManager = [[ASPINRemoteImageManager alloc] initWithSessionConfiguration:configuration]; | ||
manager = [[ASPINRemoteImageManager alloc] initWithSessionConfiguration:configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change to manager instead of sharedPINRemoteImageManager?
This method is no longer a setter but a builder.
{ | ||
NSAssert(preconfiguredPINRemoteImageManager != nil, @"setSharedPreconfiguredRemoteImageManager requires a non-nil parameter"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may should use NSParameterAssert
for the parameter check.
🚫 CI failed with log |
…ader. (TextureGroup#1197) * Allow configuring imageCache along with NSURLSessionConfiguration when initializing ASPINRemoteImageDownloader. * Update CHANGELOG.md * Update Source/Details/ASPINRemoteImageDownloader.m Co-Authored-By: wiseoldduck <[email protected]> * Put class linkage tests behind #if DEBUG * Remove silly nil check * Add non-nil assert * Update documentation
No description provided.