protocol MyClassProtocol: class {}
var delegate: MyClassProtocol? // valid warning
protocol MyProtocol {}
var delegate: MyProtocol? // invalid warning
Not sure how this can be enforced properly, but this rule is not really usable properly unless this is can be possible.
Yeah, we can't do that without changing how SwiftLint works (at least I don't see how). See https://github.com/realm/SwiftLint/issues/836#issuecomment-262671902 for more info.
Just curious: do you find yourself using this a lot? I always use : class when creating delegate/datasource protocols just to be sure to make them weak and avoid retain cycles.
We don't have that many.
Arguably, we shouldn't at all.
Perhaps it makes sense to keep it as is so that it acts as a trigger to think about it and if it is truly required, then a // swiftlint:disable:this weak_delegate should do the trick.
Actually when I wrote the rule I wondered if I should consider the case, but in fact I also wanted for the rule to enforce protocols used as delegates to always be class protocols, because that's how it should always be.
Enforcing delegates to be weak has the (good, imho) consequence of enforcing protocols to be class protocols because non-class protocols can't be marked as weak, so the aim of the rule is actually to kill two birds with one stone, enforcing both class protocols and weak.
Maybe we should just amend the warning message to make it more clear and not only warn that delegates should be marked as weak but should also be class-bound protocols?
Maybe we could make it another explicit rule that checks for protocol declarations that end with Delegate and aren't marked as : class?
Ha, could be a solution indeed 馃憤
Most helpful comment
We don't have that many.
Arguably, we shouldn't at all.
Perhaps it makes sense to keep it as is so that it acts as a trigger to think about it and if it is truly required, then a
// swiftlint:disable:this weak_delegateshould do the trick.