Skip to content

Feature/appleguice swift#21

Open
Alexs1987 wants to merge 19 commits into
tomersh:developfrom
Alexs1987:feature/appleguice-swift
Open

Feature/appleguice swift#21
Alexs1987 wants to merge 19 commits into
tomersh:developfrom
Alexs1987:feature/appleguice-swift

Conversation

@Alexs1987

Copy link
Copy Markdown

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

AlexSludnikov added 10 commits December 5, 2017 21:17
The improvements -
1. The original code went over the same classes twice. Made sure each class is only deal with once.
2. Made sure we are not traversing over NSObject, <NSObject> protocol and classes that are prefixed with UI (Like UIView, UIViewController…)
3. Got rid of recursions and implemented everything iteratively. Recursion adds couple of more seconds to the execution time.
4. appleGuiceBootstrapper.sh has an option to exclude certain files (like .frameworks) or directories (like Pods)

Overral I saw 70-80% improvement in the execution time.
…develop

# Conflicts:
#	Bootstrapper/appleGuiceBootstrapper.cpp
Example usage - Place the prefixes you want to ignore as the last parameter -
$(SHELL) $(PODS_ROOT)/AppleGuice/Bootstrapper/appleGuiceBootstrapper.sh . ./tmpAgBindings *.framework* Pods UI,NS
@tomersh

tomersh commented Mar 19, 2018

Copy link
Copy Markdown
Owner

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.

@Alexs1987

Alexs1987 commented Mar 31, 2018

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants