Create @property, @synthesize & dealloc from Variable Declaration [video]
Now a Gem!
One of the things we do a lot of in Objective-C is outlet and variable declaration, synthesize and dealloc. Since this is a repeatable recurring event I thought I would add a little automation to the process.

Comments
- you select the ivars
- choose the menu item
- paste below the closing ivar bracket
- select & copy everything below the last @property (@synthesizes and the assignments)
- Go into .m file, paste again
- select & copy the assignments below the @synthesizes
- paste into dealloc
I currently use Accessorizer: kevincallahan.org/.../... since it has every option I could ever want.
--Cheers
**UPDATE**
I just re-read your comment and the answer is that it is already being copied to the clipboard in the line preceeding the printf line.
Nice tutorial at Masters of the Void!: masters-of-the-void.com/
/var/folders/Gn/GnoTfv2rGXe3zDA8VdNuRU+++TI /-Tmp-/042842A8-7FEB-44E7-AFBC-AB425746A546-2418-00002DEDDD4F5104:10: undefined method `strip!' for nil:NilClass (NoMethodError)
from /var/folders/Gn/GnoTfv2rGXe3zDA8VdNuRU+++TI /-Tmp-/042842A8-7FEB-44E7-AFBC-AB425746A546-2418-00002DEDDD4F5104:9:in `each'
from /var/folders/Gn/GnoTfv2rGXe3zDA8VdNuRU+++TI /-Tmp-/042842A8-7FEB-44E7-AFBC-AB425746A546-2418-00002DEDDD4F5104:9
No thank you! That works like a charm now, great work!
Gary
Just one more thing Craig, thanks for adding primitives support but it still codes the @property with retain and a pointer so;
int orderCount;
generates
@property (nonatomic, retain) int *orderCount;
when of course it should be
@property (nonatomic, assign) int orderCount;
Cheers!
Gary
You might try changing the array style from:
@assign = %w( int integer BOOL float NSUInteger NSInteger )
to:
@assign = ["int", "integer", "BOOL", "float", "NSUInteger", "NSInteger"]
% xcode-select -print-path
/Developer
whereas the beta version is installed in /Developer/Developer-3.2.2beta3/.
The application's filename or POSIX path, e.g. 'TextEdit', 'TextEdit.app', '/Applications/TextEdit.app'. Where a filename is provided, appscript uses LaunchServices to locate the application. An .app suffix is optional. e.g. Given the name 'TextEdit', appscript first searches for an application with that exact filename; if none is found, it automatically adds an .app suffix ('TextEdit.app') and tries again.
It looks like LaunchServices still has the previous version as the default.
You should be able to provide the full path to target Xcode.
Replace
Xcode = app('Xcode.app')
with
Xcode = app('/Developer/Applications/Xcode.app')
I will change this in the post code as well.
Also, I took off the captcha. I'll have to find another way around the spam. ;)
In my .h file, at the top, before the @interface line, I have several @class lines, and above those, I have a couple typedef enum {...] blocks. I tested the script with one ivar selected; the @property line that your script inserts, got inserted it in multiple places: after each typedef enum {}; block, as well as after the @interface {} block. So I ended up with 3 copies of the @property declaration inside the .h file.
Thanks
originally had:
UITextField *alphaNumField;
UITextField *numericField;
Then added a few more and just did the new ivars. It somehow got the old ones stuck in its craw.
So I delete everything and start with:
UITextField *alphaNumField;
UITextField *numericField;
int mysupercoolInt;
the .H and the @property lines are great.
the .M is still has some duplication going.
@synthesize alphaNumField;
@synthesize numericField;
@synthesize mysupercoolInt;
@synthesize alphaNumField;
@synthesize numericField;
@synthesize alphaNumField;
@synthesize numericField;
dealloc has the same dups
I tried a new file, no dups from 1st. Deleted it. I added another iVar ran the script and it remembered the ivar that I did before
So now that I've deleted the Items that the Script generates and have jsut the three ivars and nothing in the .m and no @property's I get the proper number of @property, but I get all of the old ivars that I've done. Some how it remembered that I did in a previous run of the script.
In the new file I deleted the ivar I started with and created a new one with a new name. deleted the items in the .m and ran the script. The old ivar that I deleted reappeared in the .m file.
release
astus.be/.../...
- In dealloc it releases instead of setting to nil.
- Supports IBOulets.
- Set outlets to nil in viewDidUnload if you have it on your object.
pastebin.com/7qGUaJ0j
You never send a dealloc message directly. Instead, an object’s dealloc method is invoked indirectly through the release NSObject protocol method (if the release message results in the receiver's retain count becoming 0). See Memory Management Programming Guide for more details on the use of these methods.
If the prefix starts with UI (for most projects), then it would be more likely to be an IBOutlet rather than not
RSS feed for comments to this post.