You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using SwiftLint 0.27.0 I get the following false positive:
// setup view model bindings
viewModel?.profileImage.didSet(weak:self){(self, profileImage)in// << `self` in a closure should be replaced with _
if let profileImage = profileImage {self.profileImageView.image = profileImage
}else{self.profileImageView.image =UIImage(named:"avatar_100pt")}}
The underlying implementation looks like this:
import Foundation
/// A binding wrapper to track changes on constant properties.
class ObservableProperty<ValueType> {
// MARK: - Stored Instance Properties
private var didSetClosures: [(ValueType) -> Void] = []
private(set) var value: ValueType {
didSet {
didSetClosures.forEach { $0(value) }
}
}
// MARK: - Initializers
init(_ value: ValueType) {
self.value = value
}
// MARK: - Instance Methods
/// Will be called after the wrapped value is changed.
/// `$0` is the passed parameter (usually `self`), `$1` is the new value.
func didSet<WeakObject: AnyObject>(weak object: WeakObject, _ closure: @escaping (WeakObject, ValueType) -> Void) {
let weakClosure: (ValueType) -> Void = { [weak object] value in
guard let object = object else { return }
closure(object, value)
}
didSetClosures.append(weakClosure)
weakClosure(value)
}
/// Use to change the value wrapped as a variable.
func set(_ newValue: ValueType) {
value = newValue
}
}
This is an implementation of the idea also implemented in https://github.com/dreymonde/Delegated and should therefore be warning-free. My best guess is that there's some kind of exception logic going on in the rule logic for self references.
The text was updated successfully, but these errors were encountered:
AFAIK the above usage of self isn't a compiler bug anymore, instead it's a feature implemented after this proposal was accepted by the Swift Community and was shipped with Swift 4.2.
The compiler-bug was even mentioned in the proposal here. Note that I'm not using any backticks.
Jeehut
changed the title
False positive on unused_closure_paramter rule with self
False positive on unused_closure_parameter rule with self
Feb 12, 2019
Using SwiftLint 0.27.0 I get the following false positive:
The underlying implementation looks like this:
This is an implementation of the idea also implemented in https://github.com/dreymonde/Delegated and should therefore be warning-free. My best guess is that there's some kind of exception logic going on in the rule logic for
self
references.The text was updated successfully, but these errors were encountered: