Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Swift #75

Open
FGoessler opened this issue Jun 3, 2014 · 3 comments
Open

Compatibility with Swift #75

FGoessler opened this issue Jun 3, 2014 · 3 comments

Comments

@FGoessler
Copy link

The new programming language Swift is awesome but unfortunately it doesn't seem to support things like defines.
So we would need an other approach to define the dependencies of our classes without maintaining a lots of factories/providers.

Any ideas yet?

@jdewind
Copy link
Contributor

jdewind commented Jun 3, 2014

Yeah, it isn't surprising that it doesn't support preprocessor statements. However, I've adapted Objection to other languages before. Fundamentally, Objection doesn't require preprocessors macros to work. motion-objection is an example of this.

What it comes down to is whether Swift has a nice declarative programming API to work with.

@SPopenko
Copy link

SPopenko commented Jun 2, 2015

Hi guys. Do you have any updates from swift compatibility front? Will objection work with swift base project?

@glentregoning
Copy link

I've had some luck by defining a generic 'inject()' function which wraps some of the manual injection logic

public func inject<T:AnyObject>() -> T {
    return JSObjection.defaultInjector().getObject(T.self as AnyObject) as! T
}

This lets you inject dependencies into classes as follows:

class MyViewController: UIViewController {
    var network: MyNetwork = inject()
    var analytics: MyAnalytics = inject()
}

Although this is still a little experimental this has been working great for me so far.

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

No branches or pull requests

4 participants