Objective-C method name clashes on iOS categories

Hello there, I am a user of Sonarqube 9.6.1 (latest version as of today) together with the latest scanner (4.7).
We recently had an incident involving a method name defined on a category that was clashing with a private method declaration which was part of the iOS SDK (see Technical Q&A QA1908: Finding and Fixing Category Method Name Clashes for extra information about the potential issue, the resulting unpredictable behaviour and the mitigation/best practice that Apple suggests).

This non-compliance to Apple’s best practices was unfortunately not flagged by Sonarqube, is there any existing rule or any plan to add one that can flag this potential risk/non-compliance? In alternative, does anyone have a custom rule implemented that could achieve the same?

Hey there.

I’ve moved your post to the category on suggesting new rules.

It would be great if you could include a sample of code you would expect to violate such a rule and raise an issue.

Check the link, there’s examples there

Colin, any update on this?

Colin have you had a chance to review the examples? Basically Sonar would have to detect conflicting declarations of methods on categories, like the following:

@interface UIView (MyCategory)
// CORRECT: The method name is prefixed.
- (BOOL)wxyz_isOccludedByView:(UIView*)otherView;
// INCORRECT: The method name is not prefixed. This method may clash with an existing method in UIView.
- (BOOL)isOccludedByView:(UIView*)otherView;

Hello @Marco_Santarelli,

Thanks for the suggestion. I’ve raised CPP-3933 - Proposed Objective-C Rule: Categories should not provide a method already provided by its primary class to keep track of the demand for this feature.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.