@protected in Objective-C

2020-06-19 06:52发布

问题:

I have a simple class:

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>

@interface MyTableViewController : UITableViewController
{
@protected
    NSFetchedResultsController *_fetchedResultsController;
}

And one more:

#import <UIKit/UIKit.h>

@interface MyChildTableViewController : MyTableViewController
{
}

- (void)someMethod;

The problem is that I can't use _fetchedResultsController in MyChildTableViewController class. I get compile-time error: '_fetchedResultsController' undeclared (first use in this function)`

What's wrong here?

回答1:

ughoavgfhw posted right answer in comments. I've asked him (in comments, also) to rewrite it as an answer - so I can accept it. But he didn't. So I will post my own answer, simply to close the question and remove it from unanswered.

The solution:
Change C/C++ Compiler Version to LLVM compiler 2.0 in your project's settings.



回答2:

I also had the same problem, by using self->, everything worked fine.