Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto property synthesis will not synthesize property declared in a protocol even though its implemented

I got that error:

/business/Dropbox/badgers/BadgerNew/BGProfileView.m:56:17: Auto property synthesis will not synthesize property declared in a protocol

I am aware that auto property synthesis will not synthesize property declared in a protocol

So I synthesize that my self.

This is the protocol:

@protocol BGIhaveNavigationController <NSObject>

@property (readonly)UINavigationController * navigationController;//This is the problematic property

@end

@protocol BGCommonProtocol <NSObject>


@end

As for the implementation

@interface BGProfileView : UIViewController

@end

is a UIViewController and as we know UIViewController has a navigationController property. So what's wrong?

Things get problematic when I use this:

@interface BGProfileView () <BGReviewsTableDelegateProtocol>

BGReviewsTableDelegateProtocol protocol inherits BGIhaveNavigationController protocol

I can remove the warning by adding:

-(UINavigationController *) navigationController
{
    return self.navigationController;
}

But that's absurd. In a sense

-(UINavigationController *) navigationController
    {
        return self.navigationController;
    }

-(UINavigationController *) navigationController already exist through UINavigationController

like image 745
Septiadi Agus Avatar asked Jun 07 '13 06:06

Septiadi Agus


1 Answers

Use

@dynamic navigationController;

This tells the compiler that the property implementation is 'somewhere else' and that it should trust that the requirement will be fulfilled at runtime. In practice, that means its in the superclass.

If you try to implement it yourself you'll end up with duplicate storage (so things probably won't work how you expect) or recursion.

like image 174
Wain Avatar answered Oct 05 '22 16:10

Wain