Xcode 4.4 Automatic @Synthesize error in Xcode 4.3 project

It is so simple.

Lion launch.

  • I just upgraded to Xcode 4.4
  • uploaded my latest Xcode 4.3 project file
  • commented on one line of code @synthesize
  • and plenty of errors .: (

The tested compiler is installed in 'LLVM 4.0'.

Then I did the same test, but created a new project in Xcode 4.4 and voila! Auto @synthesize works in project 4.4.

Auto @synthesize also seems to be working on new properties added to the code. But the existing old one generates an error.

Does anyone else experience this? Any other things I should check?

I really want the auto-generation features to work.

Thanks.

+4
source share
3 answers

The error is not how you declare the property, but how you use it.

Autosynthesized properties create a backup storage with leading underscores by default .

So, in your code, when you have a property declared as:

@property (nonatomic, strong) UILabel *sectorLabel; 

and you automatically configure - something like this is automatically generated by the compiler:

 @synthesize sectorLabel = _sectorLabel; 

Now you can access it through the property:

 self.sectorLabel; 

Or you can access the repository directly:

 _sectorLabel; 
+5
source

I decided!

So thatโ€™s what I did.

ViewController.h

 @interface ViewController : UIViewController // Public: @property (nonatomic, strong) UILabel *sectorLabel; @end 

ViewController.m

 @implementation ViewController //@synthesize sectorLabel; 

And then this error appeared.

ViewController.m: 48: 2: use of undeclared identifier 'sectorLabel'; did you mean "_sectorLabel"?

He decided that I changed the code to:

 self.sectorLabel 

Xcode 4.3 compiled and worked perfectly, without having to have an โ€œIโ€. keyword. But Xcode 4.4 seems to have become more rigorous.

+1
source

The problem with the accepted answer is that you simply changed the behavior of your code by adding self.property.

Access to ivar compared to this property are two different things. The correct answer would be to change the code to use ivar correctly by adding an underscore.

This is not about the severity of its change in the synthesis of default properties for xcode. Also, in most style guides you will read that Apple discourages _ivar names, so I assume this is a window.

In my code I use only myself. when I intend to access through the getter and setter property. Without changing my existing code for this behavior, this is a waste of time.

0
source

All Articles