How to fix the warning "The autosynthesized property" myVar "will use the synthesized instance variable" _myVar "rather than the existing instance variable" myVar "?

I declare my .h file as follows:

#import <UIKit/UIKit.h> @interface NavigationTripViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>{ NSArray *questionTitleTrip; NSArray *questionDescTrip; NSMutableArray *answerTrip; NSMutableArray *pickerChoices; int questionInt; int totalInt; IBOutlet UILabel *questionNum; IBOutlet UILabel *questionTotalNum; IBOutlet UILabel *recordType; IBOutlet UITextView *questionDes; IBOutlet UIView *answerView; IBOutlet UIButton *preButton; IBOutlet UIButton *nextButton; UITextField *text; UIPickerView *picker; } @property (retain, nonatomic) NSArray *questionTitleTrip; @property (retain, nonatomic) NSArray *questionDescTrip; @property (retain, nonatomic) NSMutableArray *answerTrip; @property (retain, nonatomic) NSMutableArray *pickerChoices; @property (retain, nonatomic) IBOutlet UILabel *questionNum; @property (retain, nonatomic) IBOutlet UILabel *questionTotalNum; @property (retain, nonatomic) IBOutlet UILabel *recordType; @property (retain, nonatomic) IBOutlet UITextView *questionDes; @property (retain, nonatomic) IBOutlet UIView *answerView; @property (retain, nonatomic) IBOutlet UIButton *preButton; @property (retain, nonatomic) IBOutlet UIButton *nextButton; @property (retain, nonatomic) UITextField *text; @property (retain, nonatomic) UIPickerView *picker; -(IBAction)clickPre; -(IBAction)clickNext; @end 

And my .m file is like this:

 #import "NavigationTripViewController.h" #import <QuartzCore/QuartzCore.h> @interface NavigationTripViewController () @end @implementation NavigationTripViewController @synthesize questionTitleTrip,questionDescTrip,answerTripl,pickerChoices,questionNum,questionTotalNum,recordType,questionDes,answerView,preButton,nextButton,text,picker; 

All of my @synthesize variables get warnings:

The autosynthesized property myVar will use the synthesized instance variable '_myVar', a non-existing instance variable 'myVar'

In addition, the names of variables and classes used in viewDidLoad are not displayed in colors, they are simply displayed in black. Other widget controllers do not have such warnings. How to fix these problems?

+8
properties ios objective-c
source share
1 answer

Edit: Basically, for all purposes, you should build enough new Xcode to use the new behavior, in this solution you usually just remove ivar from the @interface block in the .h file ... If for any reason you need to access to ivar right now, you can declare it in the @implementation block ... and use @synthesize var or @synthesize var=_var

OGPost:

to leave, you can go to a new school and drop iVar, or you can go to an old school and add @synthesize someIvar to your @implementation block.

+17
source share

All Articles