jspahrsummers / libextobjc

A Cocoa library to extend the Objective-C programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@weakify and @strongify generate a warning about unused variable.

ignazioc opened this issue · comments

The compiler complains about an unused variable when the keyword @ weakify is used. The warning is:

Unused variable 'self_weak_'

It should be possible to fix using

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused"
 ...macro
#pragma clang diagnostic pop

to disable the warning.

Any better idea?

Just to be sure, is there a corresponding @strongify? Which version of Xcode? Could you share some code where this is happening?

Thanks for your answer.
No, there was no @strongify because was not needed in that case.

Adding @strongify Xcode doesn't complains anymore, so this means that both keywords should be used.

A @weakify by itself does nothing, other than create an unused variable as you've seen. You'll want to @strongify the variable in one of the subsequent blocks, that's the inherent idiom/pattern for these macros.