I have taken over an iOS-project which implements ReactiveCocoa 2.4.7 using CocoaPods. The app was programmed in Swift 1.2, but has later been upgraded, and is now Swift 2.3. However, ReactiveCocoa has not been updated.
I am now in a situation where my goal is to upgrade the app to Swift 3, but to do this, I will have to upgrade ReactiveCocoa as well.
In ReactiveCocoa 2.4.7, if I am correct, I am able to observe values that inherit from NSObject, as long as they have the dynamic keyword. From what I understand, this is to make it accessible to RAC which is made in Objective-C. Is there no such thing in 5.0.0? Do I have to change all my variables from
dynamic var name:String? = "MyName"
to
let name:MutableProperty<String?> = MutableProperty("MyName") ?
Is this the correct equivalent in 5.0.0?
ReactiveCocoa 2.4.7 is written in ObjC. If can upgrade the project to Swift 3 without upgrading ReactiveCocoa.
All the changes you'll have to make for ReactiveCocoa 2.4.7 to work in Swift 3 will be due to the change in how Swift 3 imports ObjC Code compared to how Swift 2 did.
See this related question. Converting to Swift 3 renamed my own Objective-C method
Regarding your equivalence question, the answer is Yes and No.
No: In RAC 2.x you could observe any property of a
NSObjectvia theRACObservemacro which works via KVO (in Swift you had to use a wrapper for the macro). For this to work with in Swift, you'll need to use thedynamickeyword for the property to enable KVO.The equivalent to this in RAC 5.0 is
DynamicProperty<Value>. However, as the documentation states:Therefore:
Yes:,
MutablePropertymost of the time is the correct equivalent. But it requires you to make more changes and will not work the same way asRACObservedid.With
RACObserveorDynamicProperty, you would just setperson.name = "Rudolph", and Observers of thenameproperty would be called.With
MutableProperty, you will have to setperson.name.value = "Rudolph".