-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Bug fix: setting properties through kf extension causes compiler error #1134
Conversation
@GarthSnyder Making the Now you can always assign class TestView: UIImageView {
func setUp() {
var kf = self.kf
kf.indicatorType = .activity
}
} |
Indeed not! How interesting... Unfortunately, I see in the git history that this protocol was for a while split into |
Hi, @GarthSnyder Thanks for updating it. I am so sorry that I didn't explain it clearly. Yes, you are right on the git history. The change to make it only This compatible helper type ( However, the getter of As you pointed out, |
Thanks for the additional comments. Did you take a look at the detailed diffs? The When the outer |
Oh, that looks great! |
Thank you for it! |
This code now crash our app. |
It is the first time we receive a report on it. These changes also work well on quite a few apps and tests without a problem. Is there a crash log or can you reproduce it in a new project? Maybe try a full clean and rebuild for your app? Or do you have any extension on Kingfisher's compatible struct? (Also worth to say if you are depending on Kingfisher in different targets, you may need to rebuild them all and keep the commit the same since the changes in this commit also affects calling convention and Swift now does not have module compatibility.) |
sorry for long delay, had a lot of work on two projects. for sure, I tried full clean (and folders cleaning) and full rebuild - nothing helped at this moment. And I don't have any code intersection - checked for it. BUT Only changes what can cause effects on it - it's simulators restarts and working computer restart. Not any other things come into my head when I thinking what else was changed. Will look at this more during my work. For now I'm used Kingfisher 5.5 version. |
Bug fix: setting properties through kf extension causes compiler error
In the current master branch (and I believe, Kingfisher 5 generally), attempting to set Kingfisher attributes through the
kf
variable ofKingfisherCompatible
causes a compiler error:The reason for this is subtle. The
KingfisherCompatible
protocol is not class-specific, so it could be conformed to by a struct. Setters are implicitlymutating
. And structs are allowed to reassignself
inside of any mutating method.However, class instances do not allow the assignment of
self
. So whenKingfisherCompatible
is adopted by a class entity, the compiler does not allow access to the setter.I know this sounds wacky; more details here and here, verified by a couple of Swift devs.
There are a couple of possible solutions.
KingfisherCompatible
could derive fromAnyObject
, which is the current version of the oldclass protocol
construct. Or you can explicitly mark the setter asnonmutating
, which seems like the better option here since it actually does nothing.