I'm currently building Reactify, a ReactiveCocoa based framework for providing apps a functional layer to build off of. It mostly focuses on UIView and UIKit for now but I'll expand in the future. One of the things that's becoming increasingly time consuming is having to re-implement all the basic reactive properties in each UIView subclass since extensions can't have stored properties.
Ideally, I'd write something like:
protocol ReactiveView {
let rac_frame: MutableProperty<CGFrame> { get }
}
extension ReactiveView {
let rac_frame: MutabeProperty<CGRect>(CGRect.zero)
}
and then extend all the UIKIt classes like so:
extension UIView: ReactiveView {}
extension UIControl: ReactiveView {}
but as I mentioned, extensions don't have support for stored properties and it's unclear if they ever will based on the current Swift evolution proposals.
I did see an answer somewhere online that had a workaround to stored properties, using associated objects but that seems like a pretty dirty hack and I'm trying to avoid using any Objective-C magic if I can help it.
Is there any way, perhaps another design pattern I haven't considered, to give all my UIView subclasses the same shared reactive properties? Keep in mind to, subclasses are somewhat necessary in this case because of all the internal implementation details in say UIControl or UIView.
Aucun commentaire:
Enregistrer un commentaire