Created
August 24, 2010 18:37
-
-
Save slmcmahon/548062 to your computer and use it in GitHub Desktop.
VI regex replace to generate synthesizers from properties.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Converts properties to synthesizers | |
1. :%s/@property (\(.*, \|\).*)\s.*\s\**\(.*\);/@synthesize \2;/g | |
2. :%s/@property (\(.*, \|\).*)\s.*\s\**\(.*\);/@synthesize \2 = _\2;/g | |
Converts properties to release calls | |
3. :%s/@property (\(.*, \|\).*)\s.*\s\**\(.*\);/ [_\2 release]; _\2 = nil;/g | |
Example: | |
input: | |
@property (nonatomic, assign) int age; | |
@property (nonatomic, copy) NSString *lastName; | |
@property (nonatomic, retain) NSString *firstName; | |
@property (copy) NSString *someOtherString; | |
output 1: | |
@synthesize age; | |
@synthesize lastName; | |
@synthesize firstName; | |
@synthesize someOtherString; | |
output 2: | |
@synthesize age = _age; | |
@synthesize lastName = _lastName; | |
@synthesize firstName = _firstName; | |
@synthesize someOtherString = _someOtherString; | |
output 3: Obviously this needs to be improved since you only want to release items that were retained | |
[_age release]; _age = nil; // bad | |
[_lastName release]; _lastName = nil; // bad | |
[_firstName release]; _firstName = nil; | |
[_someOtherString release]; _someOtherString = nil; // bad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment