Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile failed with method conflict error #595

Closed
LeeKM opened this issue Aug 4, 2016 · 7 comments
Closed

compile failed with method conflict error #595

LeeKM opened this issue Aug 4, 2016 · 7 comments
Milestone

Comments

@LeeKM
Copy link

LeeKM commented Aug 4, 2016

when i has code below in my project

class CustomView: UIView {
     weak var viewController : ViewController?
}

I got an compile error
Getter for 'viewController' with Objective-C selector 'viewController' conflicts with method 'viewController()' from superclass 'UIView' with the same Objective-C selector,is there any way to fix this problem without changing my code ?

@hackiftekhar
Copy link
Owner

hackiftekhar commented Aug 6, 2016

You are getting this because there is a ViewController method in a UIView category in my library. You could try changing your variable name.

@hackiftekhar
Copy link
Owner

I checked this and found that if UIView has other category class having same method name then library code compiles fine and works fine. This is the only issue with subclasses. So I decided to keep viewController method name as it is and doesn't change anything.

@dodikk
Copy link

dodikk commented Mar 13, 2018

@hackiftekhar , I am experiencing a similar issue. My project is using both IQKeyboardManager and a proprietary Scandit SDK

The name conflict is caused by two third-parties, so changing a property name is not an option for me.
What would you suggest?

/**
* Inside ScanditBarcodeScanner.framework
*/
@interface SBSBarcodePickerView : UIView
{
  // ...

   @property (nonnull, nonatomic, strong, readonly) SBSBarcodePicker *viewController;
}

P.S. Could you please re-consider using some sort of prefixes for your UIKit extensions?

@dodikk
Copy link

dodikk commented Mar 13, 2018

Detaching the introspection logic from UIView could be a good option too.
That would look a bit less "elegant" but a class would implicitly get the swift module's namespace and hence it would be protected from such naming conflicts.

class UIViewUtils
{
   public static func viewController(for view: UIView)->UIViewController? 
   {
        var nextResponder: UIResponder? = view
        
        repeat {
            nextResponder = nextResponder?.next
            
            if let viewController = nextResponder as? UIViewController {
                return viewController
            }
            
        } while nextResponder != nil
        
        return nil
   }


// rest of IQUIView+Hierarchy methods rewritten in the same manner
}

@dodikk
Copy link

dodikk commented Mar 13, 2018

So my workaround is making another category... In Objective-C...

#import <ScanditBarcodeScanner/ScanditBarcodeScanner.h>

@interface SBSBarcodePickerView (ViewControllerGetter)

@property (nonnull, nonatomic, strong, readonly) SBSBarcodePicker* scanVC;

@end
#import "SBSBarcodePickerView+ViewControllerGetter.h"

@implementation SBSBarcodePickerView (ViewControllerGetter)

@dynamic scanVC;

-(SBSBarcodePicker*)scanVC
{
    return self.viewController;
}

@end

@hackiftekhar
Copy link
Owner

hmm, thanks for letting me know, I'll try to change it's name with some prefix.

@hackiftekhar hackiftekhar reopened this Mar 13, 2018
@hackiftekhar hackiftekhar added this to the v6.0.0 milestone Mar 15, 2018
@hackiftekhar
Copy link
Owner

It's now fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants