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

Injecting SwiftyBeaver as logger #163

Closed
orbitbot opened this issue May 25, 2017 · 4 comments
Closed

Injecting SwiftyBeaver as logger #163

orbitbot opened this issue May 25, 2017 · 4 comments
Labels

Comments

@orbitbot
Copy link

I'm new to iOS & Swift in general, and am in the process of setting up a new project with Dip & Dip-Ui and most things according to the documentation has been going well. However, we're using SwiftyBeaver for logging in the application, and their documentation suggests setting up a global log variable like so:

import SwiftyBeaver
let log = SwiftyBeaver.self

While convenient, this also means that I need to define the same global in my unit test setups, which feels like it may cause issues. I would rather use autoInjection to provide this dependency on a per file & per test basis, but I have not been able to add something written as the SwiftyBeaver class to my container. As the linked file shows, this class does not have an explicit initializer and uses class functions for functionality.

Is there any way to "wrap" this kind of class?

@ilyapuchka
Copy link
Collaborator

Just register your logger like container.register { SwiftyBeaver.self } and resolve it with container.resolve() as SwiftyBeaver.Type, with auto-injected property it will belet logger = Injected<SwiftyBeaver.Type>()

@orbitbot
Copy link
Author

orbitbot commented May 25, 2017

Thanks for the reply. That was one of the permutations that I have already tried, it fails in compilation trying to use methods (logger.debug("sth") with

Value of type 'Injected<SwiftyBeaver.Type>' has no member 'debug'

However, did just notice that logger.value seems to have the correct methods, is this an autoinject issue or something related to the Swift "Type" (excuse my ignorance)?

@ilyapuchka
Copy link
Collaborator

That's how auto-injected properties work, you have to use value to access underlying injected instance.

@orbitbot
Copy link
Author

OK, thanks, I guess I misread the documentation a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants