-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[in_app_purchase] Fix iOS build warning #2192
Conversation
| // After querying the product, the available products will be saved in the map to be used | ||
| // for purchase. | ||
| @property(copy, nonatomic) NSMutableDictionary *productsCache; | ||
| @property(strong, nonatomic) NSMutableDictionary *productsCache; |
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.
This is the actual fixed warning, everything else in this file is cleanup. This fix may close out some bug reports where cached products can't be fetched because the dictionary is immutable, but I didn't look too hard.
warning: Property of mutable type 'NSMutableDictionary' has 'copy' attribute; an immutable object
will be stored instead
cyanglaz
left a comment
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.
LGTM!
| _requestHandlers = [NSMutableSet new]; | ||
| _productsCache = [NSMutableDictionary new]; |
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.
curious, what is the benefit of initialize them in at initialization v.s. the lazy init that we used to have?
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.
In this particular case the lazy getter wasn't threadsafe. Also this class assumes these collections are instantiated, but there's nothing stopping a subclass from overriding the getter to do something wonky that doesn't call super or set up the ivar (probably unlikely). To me it looked like it was lazily instantiated because there was no designated initializer decoration on the init methods, so there was no one canonical spot where these collections could be relied on to be instantiated.
Assuming this object is queue confined (I don't know if that's actually enforced or just convention) it's fine to keep it lazily instantiated, and I can change it back if you prefer!
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.
Thanks for the explanation. What you have now is good! LGTM again.
Description
Slight cleanup of InAppPurchasePlugin since I was editing it anyway:
Related Issues
Fixes flutter/flutter#42679.
Checklist
///).flutter analyze) does not report any problems on my PR.Breaking Change