Cannot initialize parameter and I don't understand why
Question
I get this error:
Cannot initialize a parameter of type 'id<ZXingDelegate>'
with an lvalue of type 'FirstViewController *const __strong'
From this line of code:
ZXingWidgetController *widController =
[[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES
OneDMode:NO];
How can I solve this?
Solution
Thanks to Macmade's comment I managed to solve the problem. I should have written it this way:
ZXingWidgetController *widController =
[[ZXingWidgetController alloc] initWithDelegate:***(id)** self showCancel:YES
OneDMode:NO];
Where (id) is the bridged cast he was talking about.
OTHER TIPS
use this line off code for this issue
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:(id<ZXingDelegate>)self showCancel:YES OneDMode:NO];
If I understand this correctly, problem is not that you need bridged cast, rather your FirstViewController class is not defining ZXingDelegate interface class, thus the issue.
ZXingDelegate is (based on the name I guess) interface class (protocol, or delegate) that declares functions (interface) that must be defined by class that inherits it (unless they are @optional). Something like pure-virtual (abstract) classes in C++.
So you'd need in your header file something like this:
@interface FirstViewController : UIViewController <ZXingDelegate>
And in your .m file, something like this:
@implementation FirstViewController
//......
-(void) SomeFunctionThat_ZXingDelegate_declares
{
// .... do something here....
}
//......
@end