Inherits from GBModelBase : NSObject
Declared in GBMethodData.h
GBMethodData.m

Overview

Describes a method or property.

Each instance or class method or property description contains at least one argument in the form of GBMethodArgument instance. Note that arguments should not be confused with method parameters, although they are very similar. In objective-c each method has a selector with optional parameter, followed by more parameters if applicable, with each parameter's selector delimited with a colon. appledoc on the other hand groups even the first part of the selector as an argument, however if the method doesn't have parameters, the argument's type and variable remain nil. This is how you can easily distinguish between different methods and properties:

  • Method without parameters: methodArguments array contains a single object with [GBMethodArgument argumentName] value assigned as method name and both, [GBMethodArgument argumentTypes] and [GBMethodArgument argumentVar] set to nil. Result is optional. Example: - (void)method;.
  • Method with single parameter: methodArguments array contains a single object with [GBMethodArgument argumentName] value assigned as method name, [GBMethodArgument argumentTypes] contains an array with at least one object describing the type of the parameter and [GBMethodArgument argumentVar] describing the name of the parameter variable. Result is optional. Example: - (void)method:(NSString *)var;, where argument types would contain NSString and =!= strings and argument variable var_.
  • Method with multiple parameters: methodArguments array contains at least two objects, each describing it's parameter. First instance describes the base method selector name including first parameter type and variable name. Result is optional. Example - (void)method:(NSUInteger)var1 withValue:(id)var2, where first argument would have name method, types NSUInteger and variable name var1 and second argument withValue, id and var2.
  • Properties have the same signature as methods without parameters but always have at least one result object.

To aid output templates handling, the method also prepares formatted components that can be used directly within output templates. Formatted components include all whitespace as needed to match desired coding style, so output generators can simply write the given formatted values. Although it could be argued that this should be rather part of output template, the ammount and complexity of template directives would be much greater than doing this in code. As additional bonus, we can have formatting code under unit tests to quickly verify it works as needed. And templates that really need to hande specifics, can still do so... See formattedComponents for details.

Tasks

Initialization & disposal

Method data

  •   methodType The type of method with possible values defined by GBMethodType enumeration. property
  •   methodAttributes Array of property attributes represented with NSString instances. property
  •   methodResultTypes Array of method result type components represented with NSString instances. property
  •   methodArguments Array of method arguments represented with GBMethodArgument instances with at least one object. property
  •   methodSelector Method selector that can be used for unique identification. property
  •   methodSelectorDelimiter The delimiter used for separating method arguments in methodSelector and otherwise. property
  •   methodPrefix The prefix to be written in front of the method selector. property
  •   isInstanceMethod Specified whether this method is an instance method or not. property
  •   isClassMethod Specifies whether this method is a class method or not. property
  •   isMethod Specifies whether this method is a class or instance method or not. property
  •   isProperty Specifies whether this method is a property or not. property
  •   isRequired Specifies whether the method is required or not. property

Helper methods

Other Methods

Properties

isClassMethod

Specifies whether this method is a class method or not.

@property (readonly) BOOL isClassMethod

Discussion

This is convenience accessor for simpler template handling. Internally it's equivalent to methodType == GBMethodTypeClass.

Declared In

GBMethodData.h

isInstanceMethod

Specified whether this method is an instance method or not.

@property (readonly) BOOL isInstanceMethod

Discussion

This is convenience accessor for simpler template handling. Internally it's equivalent to methodType == GBMethodTypeInstance.

Declared In

GBMethodData.h

isMethod

Specifies whether this method is a class or instance method or not.

@property (readonly) BOOL isMethod

Discussion

This is convenience accessor for simpler template handling. Internally it's equivalent to methodType != GBMethodTypeProperty.

Declared In

GBMethodData.h

isProperty

Specifies whether this method is a property or not.

@property (readonly) BOOL isProperty

Discussion

This is convenience accessor for simpler template handling. Internally it's equivalent to methodType == GBMethodTypeProperty.

Declared In

GBMethodData.h

isRequired

Specifies whether the method is required or not.

@property (assign) BOOL isRequired

Discussion

This is only used for protocols where certain methods can be marked as optional and certain as required. Default value is NO.

Declared In

GBMethodData.h

methodArguments

Array of method arguments represented with GBMethodArgument instances with at least one object.

@property (readonly) NSArray *methodArguments

Declared In

GBMethodData.h

methodAttributes

Array of property attributes represented with NSString instances.

@property (readonly) NSArray *methodAttributes

Discussion

This only applies when methodType is GBMethodTypeProperty, the value is an empty array otherwise!

Declared In

GBMethodData.h

methodPrefix

The prefix to be written in front of the method selector.

@property (readonly) NSString *methodPrefix

Declared In

GBMethodData.h

methodResultTypes

Array of method result type components represented with NSString instances.

@property (readonly) NSArray *methodResultTypes

Declared In

GBMethodData.h

methodSelector

Method selector that can be used for unique identification.

@property (readonly) NSString *methodSelector

Discussion

The selector doesn't include prefix, if you need to include that, use the value of methodPrefix.

Declared In

GBMethodData.h

methodSelectorDelimiter

The delimiter used for separating method arguments in methodSelector and otherwise.

@property (readonly) NSString *methodSelectorDelimiter

Declared In

GBMethodData.h

methodType

The type of method with possible values defined by GBMethodType enumeration.

@property (readonly) GBMethodType methodType

Declared In

GBMethodData.h

Class Methods

methodDataWithType:result:arguments:

Returns autoreleased method data with the given parameters.

+ (id)methodDataWithType:(GBMethodType)type result:(NSArray *)result arguments:(NSArray *)arguments

Parameters

type
The type of method defined by GBMethodType enumeration.
result
Array of resulting types in the form of NSString instances.
arguments
Array of arguments in the form of GBMethodArgument instances.

Return Value

Returns initialized object or nil if initialization fails.

Exceptions

NSException
Thrown if either of the given parameters is invalid.

Declared In

GBMethodData.h

propertyDataWithAttributes:components:

Returns autoreleased property data with the given parameters.

+ (id)propertyDataWithAttributes:(NSArray *)attributes components:(NSArray *)components

Parameters

attributes
Array of property attributes in the form of NSString instances.
components
Array of resulting types with last item as property name in the form of NSString instances.

Return Value

Returns initialized object or nil if initialization fails.

Exceptions

NSException
Thrown if either of the given parameters is invalid.

Declared In

GBMethodData.h

Instance Methods

formattedComponents

Returns the array of formatted components optimized for output generation.

- (NSArray *)formattedComponents

Return Value

Returns formatted components of the receiver.

Discussion

This is more or less implemented here for simpler output generator templates. Instead of programming all the conditionals in cumbersome template language, we do it in simple objective-c code, which can even be unit tested.

The result is an array of components containing NSDictionary instances with the following keys:

  • value: a NSString containing the actual value to be output. This value is always present and is neven empty string.
  • style: a NSNumber containing desired style. At this point, the only possible value is 1 for emphasized. If normal style is desired, this key is not present in the dictionary.
  • emphasized: a GRYes indicating whether the style is 1. If style is not 1, this key is missing.
  • href: a NSString containing the HTML cross reference link that should be applied with the component. If no cross reference is attached, the key is not present in the dictionary.

Declared In

GBMethodData.h

initWithType:attributes:result:arguments:

Initializes method data with the given parameters.

- (id)initWithType:(GBMethodType)type attributes:(NSArray *)attributes result:(NSArray *)result arguments:(NSArray *)arguments

Parameters

type
The type of method defined by GBMethodType enumeration.
attributes
Array of property attributes or nil if this is method.
result
Array of resulting types in the form of NSString instances.
arguments
Array of arguments in the form of GBMethodArgument instances.

Return Value

Returns initialized object or nil if initialization fails.

Discussion

This is the designated initializer.

Exceptions

NSException
Thrown if either of the given parameters is invalid.

Declared In

GBMethodData.h

mergeDataFromObject:

Merges all data from the given object.

- (void)mergeDataFromObject:(id)source

Parameters

source
Source object to merge from.

Discussion

Source object is left unchanged. If the same object is passed in, nothing happens. Subclasses should override and add their own specifics, however they should send super object the message as well! Here's overriden method example:

- (void)mergeDataFromObject:(GBModelBase *)source {
	// source data validation here...
	[super mergeDataFromObject:source];
	// merge custom data here...
}

Declared In

GBModelBase.h@71 -> GBMethodData.m