xcode 14 warning: Cannot access property 'Some_name' here in deinitializer; this is an error in Swift 6

3k Views Asked by At

When importing the IQKeyboardManager library in my project, after upgrading to XCode 14, I get these warnings in some of the imported classes:

enter image description here After making a copy of 'self', only non-isolated properties of 'self' can be accessed from a deinit.

I am getting this warning in deinit of most of the classes, I am getting this warning in some of the other third party library classes as well. I understand its meaning, but what should be the workaround for this? Any source where we can get an idea for fixing this?

2

There are 2 best solutions below

2
Mario Huizinga On BEST ANSWER

In your screenshot I can see you are using the IQKeyboardManager library in your project. The warnings are not about your code, but about the IQKeyboardManager code you have imported.

More context: swift language is changing what is and is not allowed. This specific issue is being discussed on the Swift forum. Depending on the outcome of this discussion, the IQKeyboardManager team may or may not have to change the code.

For now, I don't see a problem if you just ignore the warnings. In the future, the issue will probably be solved for you, either by the Swift team or by the IQKeyboardManager team.

I have also filed an issue on the IQKeyboardManager github.

5
JeremyP On

what should be the workaround for this?

You don't need to set anything to nil in deinit because straight after that, the memory is going to be deallocated and all of the instance variables will be "released" (using Objective-C terminology) before that happens.

Your entire deinit is redundant and can be removed. deinit in Swift is only required to clean up resources that are not managed by Swift, for example, if your object wraps a Unix file descriptor that needs to be closed.