PTHPasteboard icon

ObjC Implementation Filter

The ObjC Implementation filter converts ObjC instance variable declarations in the input text into ObjC instance method implementations. This filter parses out different components of the variable declaration and passes them into templates depending on the type of variable.

The tab for this filter's settings controls the various templates that are chosen depending on the type of instance variable in the input text.

variable type description
Object * This template is chosen for Object style variables, like the following.
  • NSString *_name;
  • NSString *title;
id This template is chosen for variables declared as type id, like the following.
  • id _name;
  • id age;
Value This template is chosen for variables declared as C basic types, like the following.
  • int _age;
  • BOOL isValid;
  • short _state
Pointer This template is chosen for Pointer style variables, like the following.
  • chat *_title;
  • void *_data

The instance variables are then broken up into different parts to be substituted into appropriate template.

substitution name description
$TYPE The ObjC type of the declaration, NSString in the following example.
  • NSString *_name;
$POINTER The pointer section of the declaration, "*" in the following example.
  • NSString * _name;
$NAME The lowercase method name derived from the instance variable, name in the following example.
  • NSString *_ name ;
$UNAME The uppercase method name derived from the instance variable, Name in the following example.
  • NSString *_ name ;
$VNAME The name of the instance variable, _name in the following example.
  • NSString * _name ;

Assuming the default templates are used the following substitutions occur.

input output
NSString *_name; - (NSString *)name
{
    return name;
}

- (void)setName:(NSString *)newName
{
    if (name != newName) {
        [name release];
        name = [newName copy];
    }
}

NSString *name; - (NSString *)name
{
    return name;
}

- (void)setName:(NSString *)newName
{
    if (name != newName) {
        [name release];
        name = [newName copy];
    }
}

unsigned int _count; - (unsigned int)count
{
    return _count;
}

- (void)setCount:(unsigned int)newCount
{
    _count = newCount;
}

char *title; - (unsigned int)count
{
    return _count;
}

- (void)setCount:(unsigned int)newCount
{
    _count = newCount;
}

NSString *_firstName;
unsigned int age;
char *title;
- (NSString *)firstName
{
    return _firstName;
}

- (void)setFirstName:(NSString *)newFirstName
{
    if (_firstName != newFirstName) {
        [_firstName release];
        _firstName = [newFirstName copy];
    }
}

- (unsigned int)age
{
    return age;
}

- (void)setAge:(unsigned int)newAge
{
    age = newAge;
}

- (char *)title
{
    return title;
}

- (void)setTitle:(char *)newTitle
{
    title = newTitle;
}

See also