Create accessor methods quickly with BBEdit
Create accessor methods quickly with BBEdit
- Subject: Create accessor methods quickly with BBEdit
- From: Matt Gemmell <email@hidden>
- Date: Sun, 12 May 2002 21:41:39 +0100
Hi all,
Thought I'd share this, since I use it myself to speed things up when
creating a new object with several instance variables. I wrote a couple
of regular expressions find/replace operations in BBEdit 6.5 (these need
6.5 or later), to quickly create implementations of accessor methods
from their declarations. For example, if you have:
- (NSString *)defaultPageName;
- (void)setDefaultPageName:(NSString *)newString;
Then run these regexps one after the other, you'll end up with:
- (NSString *)defaultPageName
{
return defaultPageName;
}
- (void)setDefaultPageName:(NSString *)newString
{
[newString retain];
[defaultPageName release];
defaultPageName = newString;
}
The first expression deals with the 'get' accessors, and the second
deals with 'set' accessors. They'll work for any number of accessor
method declarations if you do a 'Replace All'. I'd suggest writing your
accessor declarations in the .h file in PB, copying them to BBEdit,
running the regexps, then copying the result into your .m file. Make
sure that "Use Grep" is checked in BBEdit's Find & Replace dialog.
Here's pattern 1. Find:
(^- \([^\)]+\)([a-zA-Z]+));$
Replace:
\r\1\r{\r\treturn \2;\r}\r
And pattern 2. Find:
(^- \(void\)set([a-zA-Z]+):\([^\)]+\)([a-zA-Z]+));$
Replace:
\1\r{\r\t\[\3 retain\];\r\t\[\l\2 release\];\r\t\l\2 = \3;\r}
Hope someone finds these useful. They can save quite a bit of typing.
Best,
-Matt
--
Matt Gemmell
Scotland Software
<
http://www.scotlandsoftware.com/>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.