magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

How to get rid of “-Warc-performSelector-leaks” warning for Xcode12.5 with SEL IMP #1386

Open angelaTen opened 3 years ago

angelaTen commented 3 years ago

How to get rid of "-Warc-performSelector-leaks" warning with a argument based selector

Old code resulting in deprecation error with Xcode12.5

From the Magical Record repo.

#pragma clang diagnostic push
#pragma clang diagnostic ignored \
    "-Warc-performSelector-leaks"
        if (implementsShouldImport && !(BOOL)[self performSelector:shouldImportSelector withObject:relatedObjectData])
        {
            continue;
        }
#pragma clang diagnostic pop

Note: Ignoring the warning with #pragma clang diagnostic push isn't working.

Updated Logic

        if (implementsShouldImport) {
            IMP shouldImportImplementation = [self methodForSelector:shouldImportSelector];
            BOOL (*func)(id, shouldImportSelector, id) = (void *)shouldImportImplementation;
            if (!func(id, shouldImportSelector, relatedObjectData)) {
                continue;
            }
        }

Resulting in two errors:

Adopting the answer here

How to get rid of "Warc-performSelector-leaks" warning.

Magical Record is unmaintained open source library that is resulting in error with Xcode12.5 compilation.