Tricertops / Objective-Chain

Object-oriented reactive framework, inspired by ReactiveCocoa
MIT License
236 stars 19 forks source link

Using Swift, Bridging-Header.h won't find ObjectiveChain.h #5

Closed Sajjon closed 9 years ago

Sajjon commented 9 years ago

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>

"Objective-Chain/Source/ObjectiveChain.h" "ObjectiveChain/ObjectiveChain.h" "ObjectiveChain.h" When I specified the absolut path to the file, the Bridging-Header file compiled but OCAFoundation.h was not found in ObjectiveChain.h, so I never got it to compile. Maybe you can take a look at that and write an Installation Instruction in your README.md? Would be much appreciated! :)
Tricertops commented 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 ;)

Sajjon commented 9 years ago

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? :)

Tricertops commented 9 years ago

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.

Sajjon commented 9 years ago

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?

Tricertops commented 9 years ago

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.

Sajjon commented 9 years ago

Method Swizzling is Voodoo and makes the code hard to understand IMHO, but yeah making a subclass is not such a bad idea.

Thanks!

Tricertops commented 9 years ago

I agree, but some features can only be achieved with swizzling. Objective-Chain uses method swizzling on exactly 3 places: