Comments (10)
The proxy looks fantastic. If I had a choice between the two, I'd rather go with the proxy and suffer the loss of not being able to use it with non-object properties.
However, would it be impractical to offer both? Subscripting primarily for scalars, and proxies for objects?
from reactivecocoa.
I like the proxy much less now that I realize subscribables would always have to be cast. I think I would honestly rather see them wrapped in a dummy object made specifically for this purpose, like:
self.titleLabel.rac.textColor = someSubscribable.propertySomethingOrOther;
Where the subscribable's property would simply return id
.
Can go you into more detail about how exactly the keyed subscripting works?
from reactivecocoa.
@jspahrsummers Yeah I agree the cast is weak sauce :(
The keyed subscripting works something like:
#define RAC(keypath) self[RAC_KEYPATH_SELF(keypath)]
- (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
[self rac_deriveProperty:(NSString *) key from:obj];
}
RAC(self.blah.thing) = subscribable;
The really annoying bit is that the compiler has to be able to see the definition of -setObject:forKeyedSubscript:
otherwise it won't compile. So we can't just inject it at runtime.
from reactivecocoa.
@joshaber So that wouldn't work for objects that aren't relative to self
? I don't know – the keyed subscripting seems pretty picky, and probably not worth it.
from reactivecocoa.
@jspahrsummers Well, you could imagine a version that does:
#define RAC_OBJ(obj, keypath) obj[RAC_KEYPATH(obj, keypath)]
But that object would need to to implement -setObject:forKeyedSubscript:
.
Honestly, I don't really care much about that case. The case I'm specifically thinking of is UI where there are a lot of values derived from a few basic values, most/all of which are on the class itself.
from reactivecocoa.
Wait, couldn't you make the proxy-bounce situation way nicer by defining rac
to return instancetype
? Then you wouldn't have to cast. Also, you could totally make it work with non-object properties.
from reactivecocoa.
Ah, wait, totally misunderstood the problem; nevermind. I've got nothing.
from reactivecocoa.
Actually I think there's probably a way to make the keyed subscripting version more generic. I'll give a try.
The proxy bounce is really cool since it lets you pass in a subscribable in the place of a normal object but maybe there's a better / more specific way to surface that.
from reactivecocoa.
Also, what happens if you proxy bounce on a RACSubscribable
property?
Does it have to be a subscribable of subscribables? How would it know?
from reactivecocoa.
That linked PR adds the subscripting-abusive assignment. It's a little more abusive but it works without needing the class to implement -setObject:forKeyedSubscript:
.
@jspahrsummers I'm pretty sure the universe implodes. Pretty sure.
from reactivecocoa.
Related Issues (20)
- [SwiftPM on Xcode] Package resolution failed HOT 2
- Unable to compile targeting macOS Catalyst using SwiftPM (fix exists)
- why RACObserve(self.scoreStepper,value) not available? HOT 1
- App rejected for HealthKit metadata HOT 4
- UISearchBar delegate proxy crash on Mac Catalyst HOT 1
- Build error when using ReactiveCocoa via Swift Package Manager HOT 3
- can not deinit HOT 2
- Xcode12 ReactiveObj archive error HOT 3
- How to implement PIN input with attempts HOT 1
- Dispose SignalProducer created via Action HOT 1
- UnsafeKVOProperty initializer crashes after updating to ReactiveSwift 6.5.0 HOT 1
- EXC_BAD_ACCESS Cash with NSURL HOT 1
- ReactiveCocoa 11.1.0 incompatible with ReactiveSwift 6.6.0 HOT 5
- Xcode 12.5 beta 3 can't build ReactiveCocoa with SwiftPM. HOT 2
- Using "<~" binding function with Signal.Observers causes memory leaks. HOT 1
- Upgrading from very old version (2.5) fails - can't find ReactiveCocoa.h HOT 1
- Cannot remove an observer <RACKVOProxy 0x280264940> for the key path "unit" from <HGConfigureModel 0x280d25050> because it is not registered as an observer.
- Current version can't be compiled with the latest ReactiveSwift version HOT 2
- Current version can't be compiled with the latest ReactiveSwift version HOT 6
- Add output values support for interception
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactivecocoa.