Closed Sajjon closed 9 years ago
Objective-Chain will never work with Swift. It needs macros, which are missing in Swift (this is not a bug, but a feature of the language).
I’m sorry, you will have to use better language ;)
Thanks for you quick response Martin! Yes I know Swift lacks Macros, but ReactiveCocoa (RAC) is based on KVO as well, and RAC works with Swift.
But a lot of changes are being done to the RAC project currently so I don't won't to use RAC right now.
Thus I am searching for a lightweight KVO based project that I can use in Swift to make the binding between View(Controllers) and ViewModels easier in the MVVM architecture.
Do you have any idea? :)
Have you tried Block-KVO? I think it works with Swift and provides a subset of Objective-Chain (basically). You can observe key-path using block, map key-path to another and so on.
In fact, Objective-Chain is successor to the Block-KVO library.
Yes I have tried Block-KVO thanks, but I have not got it to work with UITextFields, seams like that is not possible without hooking up an IBOutlet for the text change controlEvent :(
Didn't you write Block-KVO as well? Is it possible to get it to work with UITextFields, to listen to their change and execute code without having to add a target/IBOutlet for it?
You can use custom UITextField
subclass, that listens to its own EditingDidChange
event and update some custom property.
Alternatively, if you don’t want to subclass it, you can use method swizzling, like I did in UITextField+editedText
It is not possible to use the existing .text
property for this hack.
Method Swizzling is Voodoo and makes the code hard to understand IMHO, but yeah making a subclass is not such a bad idea.
Thanks!
I agree, but some features can only be achieved with swizzling. Objective-Chain uses method swizzling on exactly 3 places:
UITextField+editingText
for KVO of edited textUIView+tintColor
for observing tintColor
changesOCADecomposer
for -dealloc
callback
Martin I did not get your project working with Swift. I draged in the project and added it in Build Phases, Link Binary With Library, I added a recursive item in Header Search Path to search for the project but did not get the Bridging Header file to find it.
I tried:
<Objective-Chain/Source/ObjectiveChain.h> <ObjectiveChain/ObjectiveChain.h>