Inherits from NSObject
Declared in GBAdoptedProtocolsProvider.h
GBAdoptedProtocolsProvider.m

Overview

A helper class that unifies adopted protocols handling.

Dividing implementation of adopted protocols to a separate class allows us to abstract the logic and reuse it within any object that needs to handle adopted protocols using composition. It also simplifies protocols parsing and handling. To use it, simply "plug" it to the class that needs to handle adopted protocols and provide access through a public interface.

The downside is that querrying code becomes a bit more verbose as another method or property needs to be sent before getting access to actual adopted protocols data.

Tasks

Initialization & disposal

Adopted protocols handling

Properties

protocols

The list of all protocols as instances of GBProtocolData.

@property (readonly) NSSet *protocols

Declared In

GBAdoptedProtocolsProvider.h

Instance Methods

initWithParentObject:

Initializes ivars provider with the given parent object.

- (id)initWithParentObject:(id)parent

Parameters

parent
The parent object to be used for all registered ivars.

Return Value

Returns initialized object.

Discussion

The given parent object is set to each GBIvarData registered through registerIvar:. This is the designated initializer.

Exceptions

NSException
Thrown if the given parent is nil.

Declared In

GBAdoptedProtocolsProvider.h

mergeDataFromProtocolsProvider:

Merges data from the given protocol provider.

- (void)mergeDataFromProtocolsProvider:(GBAdoptedProtocolsProvider *)source

Parameters

source
GBAdoptedProtocolsProvider to merge from.

Discussion

This copies all unknown protocols from the given source to receiver and invokes merging of data for receivers protocols also found in source. It leaves source data intact.

Declared In

GBAdoptedProtocolsProvider.h

protocolsSortedByName

Returns the array of all protocols sorted by their name.

- (NSArray *)protocolsSortedByName

Declared In

GBAdoptedProtocolsProvider.h

registerProtocol:

Registers the given protocol to the providers data.

- (void)registerProtocol:(GBProtocolData *)protocol

Parameters

protocol
The protocol to register.

Discussion

If provider doesn't yet have the given protocol instance registered, the object is added to protocols list. If the same object is already registered, nothing happens.

Note: If another instance of the protocol with the same name is registered, an exception is thrown.

Exceptions

NSException
Thrown if the given protocol is already registered.

Declared In

GBAdoptedProtocolsProvider.h

replaceProtocol:withProtocol:

Replaces the given original adopted protocol with the new one.

- (void)replaceProtocol:(GBProtocolData *)original withProtocol:(GBProtocolData *)protocol

Parameters

original
Original protocol to replace.
protocol
The protocol to replace with.

Discussion

This is provided so that processor can replace known protocols "placeholders" with real ones..

Exceptions

NSException
Thrown if original protocol is not in the current protocols list or new protocol is nil.

Declared In

GBAdoptedProtocolsProvider.h