3

I try to create a library called MyLib using RxSwift as dependency, which using cocoapod command pod lib create. However, the following code doesn't work.

import UIKit
import MyLib

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    // compile error: Use of unresolved identifier 'Observable'
    Observable.just("")
  }

}

It only works after I add import RxSwift

I would like to just import MyLib only, have any ideas?

Thanks!

jaychang0917
  • 1,880
  • 1
  • 16
  • 21
  • Why you can't just use `import RxSwift`? `Observable` isn't your class so with respect to RxSwift developers it is advisable to use this import – Adrian Bobrowski Oct 19 '17 at 04:18
  • Then the user of my library need to import MyLib and RxSwift, if my library depends on other 4 dependencies, then the user need to import many dependencies in order to use my library – jaychang0917 Oct 19 '17 at 04:23
  • 1
    Have you tried using typealias for `Observable` in your library? For example: `public typealias Observable = RxSwift.Observable` – Adrian Bobrowski Oct 19 '17 at 04:26
  • AFAIK most module system does this. Additionally, the user may not really need all those imports anyway. If the dependency is contained in you library and not used directly by the user. – Shane Hsu Oct 19 '17 at 05:05
  • 4
    Possible duplicate of [iOS framework with dependencies](https://stackoverflow.com/questions/14194577/ios-framework-with-dependencies) – Hexfire Oct 19 '17 at 05:07
  • @AdrianBobrowski i think `public typealias` is what I want, do you mind to reply this topic? so I can mark yours as the answer. – jaychang0917 Oct 19 '17 at 06:52

1 Answers1

4

Observable isn't your class so with respect to RxSwift developers it is advisable to use this import.

But if you really want then try use typealias for Observable in your library?

For example: public typealias Observable = RxSwift.Observable

Adrian Bobrowski
  • 2,681
  • 1
  • 16
  • 26