View on GitHub

Alchemic v2.1

An advanced DI framework for iOS

Carthage compatible

API: Objective-C Swift 3

HomeInstallationAdding AlchemicArchitectureObject factoriesInjectionsValue typesProgrammatic usageiOS featuresAdvanced usageError handlingReference

Alchemic reference

Core

Function/Macro Description
AcRegister(…) Declares a class factory. Optional arguments can be used to further configure it.
AcInitializer(selector, …) Specifies an initializer to be used when instantiating a class. Option arguments specify where to get the values from for any initializer arguments.
AcMethod(return-type, selector, …) Registers a method as an object factory. If the method is an instance method, then Alchemic will make sure the class is instantiated first. If the method is a class method then it is called directly. Also takes the same configuration arguments as AcRegister. Optional arguments specify where to get the values from for any method arguments.
AcInject(variable, …) Declares an injection. If no arguments are specified, Alchemic will interrogate the runtime for the variables type data and build some model search criteria based on that.
AcFactoryName(name) Configuration option for AcRegister and AcMethod tags. Specifies a custom name to store the object factory under in the model.
AcTemplate Configuration option for AcRegister and AcMethod tags. Indicates that the object factory is to behave like a template, creating new instances of the class every time an object is requested. AcSet cannot be used with a template because the object factory will never store a value.
AcPrimary Configuration option for AcRegister and AcMethod tags. Indicates that the object factory is considered more important that other object factories when considering possible candidates for injection. If primary object factories are returned in a model search, all other object factories will be ignored.
AcReference Configuration option for AcRegister and AcMethod tags. Puts the object factory into reference mode. In this mode the object factory will not generate any objects. Instead it will wait to be given an object to be stored for injection. Attempting to inject an object from a reference object factory which no value has been stored will throw an exception unless the factory is also configured with the AcNillable option.
AcNillable Configuaration option for AcRegister and AcMethod tags. Indicates that the object factory is allowed to have a nil value. This is often teamed with the AcWeak tag.
AcWeak Configuration option for AcRegister and AcMethod tags. Weak object factories store weak references to the objects they have created or stored. This stops the object factory from creating memory leaks when dealing with objects (such as UIViewController instances) which are not always present.
AcTransient Configuration option for AcInject. Specifies that the variable injection is regarded as transient. Effectively this means that Alchemic will watch the object factories that supplied objects for the injection and if any change their stored references, Alchemic will re-inject the dependency automatically.
AcArg(arg-type, …) Used to declare arguments for AcInitializer and AcMethod tags. The arg type is the expected type of the method argument. Optional arguments can then be added to define where the value for the argument comes from. AcArg is most useful where the search criteria for a value is a different type to the argument.
AcGet(return-type, …) Can be used inline with your code to retrieve a value from Alchemic. The retunr type is the type that Alchemic is expected to return. This will be used for any autoboxing required. If there are no search criteria after the return type, then it will be examined to deduce a matching search criteria.
AcSet(value, …) Can be used inline with your code to set a value in an Alchemic object factory. After the value to be set, you can specify search criteria to be used to find the obejct factory to be set. If not specified the type of the value will be used as a search critieria.
AcClass(class-name) Used when you need to search for one or more object factories in the model. Searches the model for object factories that manage objects of the specified class. There can only be a single instance of AcClass in any search criteria.
AcProtocol(protocol-name) Used when you need to search for one or more object factories in the model. Searches the model for object factories that manage objects which conform to the specified protocol. You can used as many of these as you see fit in a search criteria.
AcName(object-factory-name) Used when you need to search for one or more object factories in the model. USed when you know the name of the object factory you want to retrieve. Cannot be used with AcClass and AcProtocol.

Utility

Function/Macro Description
AcWeakSelf Useful macro for declaring a weak reference to self. Functionally equivalent to
__weak __typeof(self) weakSelf = self
Use before creting a block that will be executed outside of the current routine. Helps to stop circular retain cycles.
AcStrongSelf Use within a block that will be executed out side the current scope. Declares a local strong reference to a previously declared weak reference. Use in tandom with AcWeakSelf for best effect. Functionally equivalent to
__typeof(self) strongSelf = weakSelf
AcIgnoreSelectorWarnings(code) Mainly used when declaring selectors from other classes and selector warnings are turned on. Pushes a new clang diagnostic scope, turns off selector warnings, includes the passed code then pops the scope.

Constants

Constants are for setting contant values for method arguments, injections, etc.

Constant example Swift ACLType Type
AcBool(YES) ALCType.bool BOOL
AcChar(‘x’)   char
AcCString(“abc”)   char *
AcDouble(1.23456)   double
AcFloat(1.2f)   float
AcInt(5)   int
AcLong(5)   long
AcLongLong(5)   long long
AcShort(5)   short
AcUnsignedChar(‘x’)   unsigned char
AcUnsignedInt(5)   unsigned int
AcUnsignedLong(5)   unsigned long
AcUnsignedLongLong(5)   unsigned long long
AcUnsignedShort(5)   unsigned short
AcCGFloat(1.23456f)   CGFloat
AcCGSize(CGSizeMake(1.0f, 2.0f))   CGSize
AcCGPoint(1.0f, 2.0f)   CGPoint
AcCGRect(1.0f, 2.0f, 3.0f, 4.0f)   CGRect
AcString(@”abc”)   NSString *
AcNil   nil