Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jul 22 01:42
    dependabot[bot] labeled #173
  • Jul 22 01:42
    dependabot[bot] opened #173
  • Jul 22 01:42

    dependabot[bot] on bundler

    Bump tzinfo from 1.2.5 to 1.2.1… (compare)

  • Jun 22 21:53

    StephaneMagne on 1.1.2

    (compare)

  • Jun 22 21:52

    StephaneMagne on master

    Fix builder function name. Bump version to 1.1.2 Merge pull request #172 from sc… (compare)

  • Jun 22 21:52
    StephaneMagne closed #172
  • Jun 22 21:52
    StephaneMagne opened #172
  • Jun 22 21:52

    StephaneMagne on fix_nested_builder

    Fix builder function name. Bump version to 1.1.2 (compare)

  • Jun 22 20:36

    StephaneMagne on fix_nested_builder

    (compare)

  • Jun 21 23:32

    StephaneMagne on 1.1.1

    (compare)

  • Jun 21 23:29
    StephaneMagne closed #171
  • Jun 21 23:29

    StephaneMagne on master

    Add support to nest input conta… Update version to 1.1.1 Merge pull request #171 from sc… (compare)

  • Jun 21 23:29
    StephaneMagne opened #171
  • Jun 21 23:28

    StephaneMagne on fix_nested_input_container

    Add support to nest input conta… Update version to 1.1.1 (compare)

  • Jun 15 18:05
    StephaneMagne commented #152
  • Jun 15 18:04
    StephaneMagne commented #152
  • Jun 15 18:00
    StephaneMagne commented #160
  • Jun 15 17:31
    StephaneMagne commented #170
  • Jun 15 17:22
    StephaneMagne closed #164
  • Jun 15 10:43
    petropavel13 opened #170
Theophane RUPIN
@trupin
Welcome to the Weaver room! Don't hesitate to send over your questions/suggestions and I'll be happy to answer :smiley:
corban123
@corban123
Is there a way to test out a Weaver implementation in a Playground, or does it require AppDelegate
Theophane RUPIN
@trupin
Hi @corban123, there is no Playground, but there's a sample in the repository --> https://github.com/scribd/Weaver/tree/master/Sample
Because a Weaver is a tool which runs before a project's compilation, a Playground wouldn't have been the best fit for a complete demo
corban123
@corban123
Is there a reason why in that sample you sent, those files in the API folder are unable to use the property wrapper for Weaver?
corban123
@corban123

Also, is there a way to avoid having all the registrations occur in AppDelegate?

EG:
I have services ServiceA and ServiceB used by ViewModelA. Is there a way to have something like a class APIContainer that contains the registrations for ServiceA and ServiceB and have appDelegate register APIContainer and ViewModelA, while allowing ViewModelA to use those services register in the APIContainer?

I'm worried that if you have a conglomeration of services, your AppDelegate is going to look Disgusting
@trupin Makin sure to mention that this question is for you haha
Theophane RUPIN
@trupin

Is there a reason why in that sample you sent, those files in the API folder are unable to use the property wrapper for Weaver?

There's no reason why Weaver couldn't use property wrappers in the API folder. I could actually update that to avoid confusion.

Also, is there a way to avoid having all the registrations occur in AppDelegate?

Absolutely, Weaver is designed so that you can register your dependencies anywhere is best for you.

corban123
@corban123
Do you have any example of that happening? I created a class called APIRegistration using the example project provided, set @Weaver(.registration, type: MovieAPI.self, builder: AppDelegate.makeMovieAPI) private static var movieAPI: APIProtocol in there, then attempted to make use of MovieAPI in the ReviewManager and it's saying Dependency cannot be resolved.
Theophane RUPIN
@trupin
I would need more detail about your code to be able to tell you what's going on. One thing I can see right now, which might be unrelated for the error you're seeing, is that you're declaring movieAPI as a static, which won't work.
As for an example, you can look at HomeViewController.swift:26 or MovieViewController.swift:39
These are dependencies registered and used at their point of registration
corban123
@corban123

I'll try to post it as well as I can.

I have a class APIRegistration that looks like this

class APIRegistration {

    @Weaver(.registration, type: MovieAPI.self, builder: makeMovieAPI)
    private var movieAPI: APIProtocol


    func makeMovieAPI(_ dependencies: MovieAPIInputDependencyResolver) -> APIProtocol {
        return MovieAPI(urlSession: dependencies.urlSession)
    }
}

And then in my AppDelegate I register APIRegistration

class AppDelegate { 
    @Weaver(.registration, type: APIRegistration.self)
    private var api: APIRegistration
    }

and then in my HomeViewController (Which is presented by my AppDelegate) I have

class HomeViewController { 
...
@Weaver(.reference)
        private var movieAPI: APIProtocol
}

However, it says that Invalid dependency: 'movieAPI: APIProtocol'. Dependency cannot be resolved

Unless I'm missing something, it looks like only children of the object that's registering things can access what has been registered. What I'm looking for is a way to register App-Wide services separately from the AppDelegate

Theophane RUPIN
@trupin
It looks like you're never registering HomeViewController anywhere. For Weaver to find movieAPI and inject it in HomeViewController, it needs to know where HomeViewController is registered in the dependency graph. If you're not ready to register HomeViewController or if you want to build it manually, you can use // weaver: self.isIsolated = true in HomeViewController which indicates Weaver to not try validating its dependencies and generate a classic builder instead.
corban123
@corban123
Ah, I should mention this is built on top of the sample code you linked yesterday, so I'm currently registering HomeViewController in the AppDelegate seen here:
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    private let dependencies = MainDependencyContainer.appDelegateDependencyResolver()

    @Weaver(.registration)
    private var logger: Logger

    @Weaver(.registration, builder: AppDelegate.makeURLSession)
    private var urlSession: URLSession

    @Weaver(.registration, type: APIRegistration.self)
    private var api: APIRegistration

    @Weaver(.registration, type: ImageManager.self)
    private var imageManager: ImageManaging

    @Weaver(.registration, type: MovieManager.self, builder: AppDelegate.makeMovieManager)
    private var movieManager: MovieManaging

    @Weaver(.registration, type: HomeViewController.self)
    @objc private var homeViewController: UIViewController

    // weaver: reviewManager = ReviewManager <- ReviewManaging
    // weaver: reviewManager.objc = true

    func applicationDidFinishLaunching(_ application: UIApplication) {

        window = UIWindow()

        window?.rootViewController = UINavigationController(rootViewController: homeViewController)
        window?.makeKeyAndVisible()
    }
}
Alexander Puchta
@alexanderpuchta
Is there an example for using Weaver with SwiftUI? currently struggling with this.