diogocarmo
diogocarmo

Reputation: 970

Property vs RACSignal

I just started with ReactiveCocoa (and FRP for that matter) and every time I start refactoring my code to be more RAC-based, I ask myself: when should I create a property or a RACSignal?

For example, if I have a ViewModel that does some checking to see if a button can be enabled or not, should I do this:

dynamic var ready: NSNumber //Bool

Or this:

var ready: RACSignal

Upvotes: 1

Views: 488

Answers (2)

Ash Furrow
Ash Furrow

Reputation: 12421

If you want to start writing more RAC-based code, then I would highly encourage you to use a RACSignal instead of a value property, for two reasons:

  1. RACSignal use on view models is arguably more idiomatic (i.e.: a more "RAC" way of doing things).
  2. Not having access to the property value at any given time will force you to think in terms of FRP, helping you learn RAC faster.

Upvotes: 3

Rui Peres
Rui Peres

Reputation: 25917

I guess it depends on your use case. If it's a continuous stream of events, it might make sense to use the RACSignal approach. if it's a one time thing, a Bool could suit you.

Upvotes: 3

Related Questions