IPhone Xcode automatic property, synthesis and delloc

I have been developing the iPhone for the last 1-2 months, and all the time to accept IBOutlet, I use the following method to declare any property:

In .h files:

@interface .... { controlType varName; } @property() IBOutlet controlType varName; 

In .m files:

upstairs -

 @synthesize varName; 

in delloc method - [varName release];

Although the method is good, itโ€™s not very good when it takes a couple of minutes just to declare the property.

Is there any automatic process for declaring properties, IBOutlets, IBActions, or basic variable data.

I hope there should be some automatic methods for this scenario, as this is a very simple process.

Thanks to everyone.

+6
iphone xcode refactoring
source share
5 answers

In fact, yes!

You no longer need to declare the actual iVar.

In short, just leave this part: controlType varName;

Now you still need to explicitly โ€œsynthesizeโ€.

(As far as I can tell, they could automate this in the future. But for now, you need to โ€œsynthesizeโ€ to create a setter and getter.)

You still need to free up memory - there really is no way to automate it, since memory processing is "real programming."

For any new readings, do not forget the self. part when using this property.

Plus, note that Xcode4 even has a new automatic thing. Just drag and drop from the interface designer to your .h file and it will do everything for you - try it!


In answer to your question with the inscription: IBOutlet MUST BE PROPERTY MUST - you can simply use the usual cheap iVar. On the other hand, if you want, you can use the property. Also: you can even use the new trick (2011) so you donโ€™t bother to declare ivar, just use the property declaration and run IBOutlet there!

+4
source share

Another that few people know about is that you can drag and drop from the Builder interface to the header file to create IBActions or IBOutlets.

NOTE: Open the assistant editor, focusing on the XIB inside IB.

If you create IBOutlets this way, Xcode automatically adds the property, synthesizes it, sets it to nil in viewDidUnload, and frees it in dealloc.

You simply drag and drop the IB object into the header file in the same way as when creating connections between the view objects and their file owners (screenshot below). enter image description here

+8
source share

There is a terrific tool that speeds up the whole process: accessorizer .

You write controlType varName; select it and click a few buttons, and the accessorizer will create the property, init, dealloc, viewDidUnload and much more for you. You just need to paste the code into your project.

Try it, there is a demo.

+2
source share

You can save yourself to free an object by changing the property declaration. If you use:

 @property (assign) IBOutlet controlType varName; 

save will not be in your opinion, so you do not have to release it later. This is generally safe, because views persist when they are added to parents. If for some reason you delete views from your parent, you will have to save them.

0
source share

Here is an xcode script to automate the tedious declaration of properties.

0
source share

All Articles