observando contentSize (CGSize) con KVO en swift
Estoy tratando de observarcollectionView.contentSize
Me gusta esto :
func startObserveCollectionView() {
collectionView.addObserver(self, forKeyPath: "contentSize", options: NSKeyValueObservingOptions.Old.union(NSKeyValueObservingOptions.New), context: &SearchDasboardLabelContext)
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if context == &SearchDasboardLabelContext {
if object === collectionView && keyPath! == "contentSize" {
print(change)
}
}
}
y en el terminal xcode obtuve unNSSize
noCGSize
Me gusta esto :
Optional(["old": NSSize: {320, 0}, "new": NSSize: {375, 39.5}, "kind": 1])
En el objetivo-c utilicé el métodoCGSizeValue
CGSize newContentSize = [[change objectForKey:NSKeyValueChangeNewKey] CGSizeValue];
¿Hay algún método comoCGSizeValue
en rápido
Lo he intentado rápidamentevar newContentSize = change[NSKeyValueChangeNewKey]?.CGSizeValue()
pero tengo error
no se pudo encontrar el miembro 'CGSizeValue'
necesita ayuda a alguien? Gracias