1

I use RxSwift at work (ont a big fan, too complex, but really powerful indeed), and I want to try to use PromiseKit as a "smaller" tool.

I try to create sort of an Observable with PromiseKit, but I can't figure it out. I tried to use the NSObject's extension observe(key path: String) -> Promise, but it does not seems to work.

I noted that I have a struct (hence does not inherit from NSObject) and I tried to observe an NSObject, but it does not seems to work.

Here's what I've done :

in my controller that has the value I want to observe, I declared a variable as follows :

lazy var homeworkPromise: Promise<Homework> = self.observe(keyPath: "homework")

Somewhere in my code, I update the value of the homework variable.

And in my presentingVC, here's what I do :

create.homeworkPromise
            .then(execute: { h -> Void in
            print(h)
        })

It seems pretty straightforward to me, but I guess I'm missing something ;-) Thanks for your help.

Khal
  • 790
  • 5
  • 23
  • This should work. Does it work with regular KVO? – mxcl Nov 27 '17 at 16:45
  • 1
    Unlike Observables, once a promise is fulfilled it cannot be reset. It isn't appropriate to use a Promise as a KVO type observer. – Daniel T. Nov 28 '17 at 01:53
  • @mxcl it does not actually, but I can't figure out why :-/ – Khal Nov 28 '17 at 13:46
  • 1
    K, well seems like your problem is before PromiseKit. – mxcl Nov 28 '17 at 17:54
  • Well I'll investigate that, though I already did and I cannot understand what is wrong with the KVO :-/ Thanks anyway. Can you post an answer with this replay so that I can mark it as resolved and vote for your answer? Thanks @mxcl ;-) – Khal Nov 30 '17 at 07:13

0 Answers0