onevcat / Kingfisher

A lightweight, pure-Swift library for downloading and caching images from the web.
MIT License
23.13k stars 2.64k forks source link

remove redundant code #2284

Closed P4VEMENT closed 3 weeks ago

P4VEMENT commented 3 weeks ago

Remove redundant assignments of totalCostLimit and countLimit to memory storage properties since the config setter already did it.

onevcat commented 3 weeks ago

@P4VEMENT Thanks for this.

However, if I recall correctly, the didSet of a stored property isn’t triggered when it’s assigned within the initializer. Could you confirm if this change is necessary and ensure it won’t alter the current behavior?

Or maybe we can have a better way to improve this, for example extract the duplicated code into a helper method, etc.

P4VEMENT commented 3 weeks ago

As a beginner in the Swift language, thank you for the reminder. The official documentation states that "The willSet and didSet observers of superclass properties are called when a property is set in a subclass initializer, after the superclass initializer has been called. They aren’t called while a class is setting its own properties, before the superclass initializer has been called." I believe the current code is already sufficiently concise, so I will close this pull request.