We put together some macros that we've found useful and thought you might as well. Have any of your own?
Please submit them to us and we'll share them here with anyone else that's interested.
We'd love to build up a community of Text Bucket users contributing and providing snippets to help automate things for
everyone.
To copy in to Text Bucket, just highlight the snippet and bring Text Bucket up. Then press the number of the
empty slot you would like to place it in.
|
Cocoa snippets
|
Objective-C 1.0 accessor/mutator |
By Jim Thomason |
Set this to execute as a perl script, and it will create an accessor/mutator combo based off of the selected text |
|
use strict;
use warnings;
my $accessor = "S#SELECTION#";
my $mutator = "set" . ucfirst($accessor);
my $newVar = "new" . ucfirst($accessor);
print qq[
-(M#TYPE=id#) $accessor {
return $accessor;
}
-(void) $mutator:(M#TYPE#) $newVar {
[$newVar retain];
[$accessor release];
$accessor = $newVar;
}
];
|
Objective-C 2.0 properties from attributes |
By Jim Thomason |
Set this to execute as a perl script, and deselect "Send results to calling application". Highlight your object's list of attributes, then invoke Text Bucket.
This will place on the clipboar a set of Objective-C 2.0 style properties. |
|
use strict;
use warnings;
my $properties = "S#SELECTION#";
$properties =~ s/\s+/ /g;
$properties =~ s/;//g;
my @properties = grep {length} split /\s+/, $properties;
die "Please provide type/attribute" if @properties % 2;
my $eol = @properties > 2 ? "\n" : '';
while (@properties) {
my $type = shift @properties;
my $attribute = shift @properties;
my $assignment = 'assign';
$assignment = 'retain' if $type eq 'id' || $type =~ /\*/ || $attribute =~ /\*/;
print "\@property ($assignment) $type $attribute;$eol";
}
|
Objective-C 2.0 synthesized accessors |
By Jim Thomason |
Set this to execute as a perl script, and deselect "Send results to calling application". Highlight your object's list of attributes, then invoke Text Bucket.
This will place on the clipboard a set of Objective-C 2.0 style synthesized attributes. |
|
use strict;
use warnings;
my $properties = "S#SELECTION#";
$properties =~ s/\s+/ /g;
$properties =~ s/;//g;
my @properties = split /\s+/, $properties;
while (@properties) {
my $type = shift @properties;
my $attribute = shift @properties;
print "\@synthesize $attribute;\n";
}
|
Perl snippets
|
accessor and mutator |
By Jim Thomason |
Set this to execute as a perl script. Highlight your object's list of attributes, then invoke Text Bucket.
This will return a set of standard perl-ish looking accessors and mutators. |
|
use strict;
use warnings;
my $accessor = "S#SELECTION#";
my $mutator = "set" . ucfirst($accessor);
print qq[
sub $accessor {
my \$self = shift;
\$self->{"$accessor"} = shift if \@_;
return \$self->{"$accessor"};
}
sub $mutator {
my \$self = shift;
my \$newVal = shift or die "Cannot mutator w/o value";
\$self->{"$accessor"} = \$newVal;
}
];
|