AppleGuice
AppleGuice copied to clipboard
Feature/appleguice swift
This PR brings the ability to auto inject into swift classes.
Writing something like that in a swift class (That inherits eventually from NSObject)
@objc var _ioc_testService: TestServiceProtocol?
Will cause AppleGuice to auto inject the implementation.
Moreover, in order for NSProtocolFromString
and NSClassFromString
to work (Which are used extensively in AppleGuice code to read the mappings in the bootstrapper), we need to pass it something like that ${MODULE_NAME}.{PROTCOL_NAME}
(For example MyAwesomeFramework.MyAwesomeService).
To get the module name we need to let the bootstrapper know in which module the current swift class/protocol resides. That we do by defining in each swift target/Dynamic framework a protocol called ${MODULE_NAME}AppleGuiceModule
. Each injectable class/protocol in the module must conform to this protocol. That way the bootrapper will know how to represent the MyAwesomeService in the dynamic framework MyAwesomeFramework to MyAwesomeFramework.MyAwesomeService
Hey Alex,
thank you for your code contribution.
I noticed you haven't change readme.md
to reflect your changes.
Also, IvarAccess.h
is a piece of code by @johnno1962. Including it in this repository means taking ownership over it, which is not something I'm keen to do.
You can create a private podspec for that file and include it as a dependency using Cocoapods.
Hey Tomer,
I've added more unit tests for AppleGuiceInjector
to cover the swift use cases, updated the Readme and moved the IvarAccess file to a separate pod - SwiftIvarAccess
.