Comments (5)
If will fire if you change its dynFrame
property.
If you really need to observe frame
changes, you could create a Dynamic from KVO:
class customView:UIView{
...
lazy var frameListener:Bond<CGRect> = Bond<CGRect>(){ [unowned self] frame in
println("firing :D")
}
func bind() {
dynamicObservableFor(self, keyPath: "frame", defaultValue: CGRectZero) ->| frameListener
}
}
https://github.com/SwiftBond/Bond#key-value-observing
from bond.
Thank you, got it for dynFrame
Using Bond 3.7.2, I was playing with dynamicObservableFor
but it throw me an error during the cast of the generic T on this line
public func dynamicObservableFor<T>(object: NSObject, #keyPath: String, #defaultValue: T) -> Dynamic<T> {
...
let value: T = (keyPathValue != nil) ? (keyPathValue as? T)! : defaultValue
Could not cast value of type 'NSConcreteValue' (0x1740576b8) to 'C.CGRect' (0x1002c5f80)
i'll try to find out what is going wrong
from bond.
I had to use NSValue
for the defaultValue
and map to CGRect
because object.valueForKeyPath(keyPath)
return an NSValue
now it works great !
dynamicObservableFor(self, keyPath: "frame", defaultValue:NSValue(CGRect: CGRectZero)).map{$0.CGRectValue()} ->| frameListener
is there a better way ?
from bond.
Yeah, that's due to unfortunate differences between ObjC and Swift. There is another way to create Dynamic from KVO property. It allows you to manually convert object. You need to pass two closures. One that converts AnyObject? to CGRect, and one other way round.
dynamicObservableFor(self, keyPath: "frame", from: { $0?.CGRectValue() ?? CGRectZero }, to: { NSValue(CGRect: $0) })
from bond.
The second way seems to be better
You've done an amazing job with Swift Bond, thank you!
from bond.
Related Issues (20)
- Cannot emulate VC lifecycle event HOT 1
- Feed() using collection view's sizeForItemAt delegate selector crashes on iOS 13
- MutableObservableArray2D replace items can't use performdiff
- Cocoapods latest version HOT 1
- Project file uses SRCROOT; should be PROJECT_DIR HOT 2
- Correct way to update MutableObservableArray2D from signals
- No (understandable) migration documentation for NSTableView binding
- Incorrect operator precedence in OutlineViewBinder.(_:,isExpandable:)
- Regarding .Framework file.
- Xcode build error: Header 'ReactiveKit-Swift.h' not found
- Cannot not build source code from the latest version on Xcode 12.3
- Wrong generic use of ObservableArray/MutableObservableArray?
- viewForSupplementaryElementOfKind and bidirectional binding HOT 1
- Control Event not triggered when setting data inside viewModel to textField
- Installation problems Xcode Version 12.4 (12D4e)
- Incorrect MutableObservableArray difference
- Error building app with Xcode 12.5 HOT 4
- Swift Package Manager Dynamic Libraries
- Unable to run in simulator on M1 Macs HOT 6
- Not able to build Bond Version 7.8.0 in Xcode 14 & 15
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 bond.