Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior

Details

Xcode: 9.2, 10.2, 11.0 (11A420a)

Warnings in Objective-C Pods

I have swift project. Warning Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior appears when I use Objective-C pods:

  • Bolts
  • FBSDKCoreKit
  • FBSDKLoginKit

enter image description here

Solution 1 (manual)

CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO

Solution 2 (automatic)

Add to the end of your Podfile:

post_install do |installer|
      installer.pods_project.targets.each do |target|
           target.build_configurations.each do |config|
                config.build_settings['CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF'] = 'NO'
           end
      end
 end

Results

enter image description here


Replacing myTimer by self->myTimer would fix your warning.

When you use an iVar _iVar in the code, the compiler will replace the code by self->_iVar, and if you use it inside a block, the block will capture self instead of the iVar itself. The warning is just to make sure the the developer understand this behaviour.


For those of you getting these warnings because of Bolts/FBSDKCoreKit/FBSDKLoginKit, you should avoid Vasily's answer and instead silence the warnings for those specific dependencies.

Option 1

Mention each pods instead of just FacebookCore and add inhibit_warnings: true

pod 'FacebookCore', inhibit_warnings: true
pod 'Bolts', inhibit_warnings: true
pod 'FBSDKCoreKit', inhibit_warnings: true
pod 'FBSDKLoginKit', inhibit_warnings: true

Option 2

Or silence all pods, by adding to your Podfile this:

inhibit_all_warnings!

Conclusion

You'll still get warnings for your own code. Not getting those could be problematic at some point, that's why I believe it's a better solution.

Next time you update the Facebook sdk, see if you can remove the inhibit_warnings: true or inhibit_all_warnings!.