<div dir="ltr">myView.layer.sublayers returns an array of CALayer objects. Some of my sublayers are CAShapeLayers. I want to act on the CAShapeLayer objects.<div><br></div><div>Shouldn't flatMap allow me to conditionally cast CALayers to CAShapeLayers? i.e. </div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>let layers = myView.layer.sublayers.flatMap({ $0 as? CAShapeLayer })</div><div><br></div></blockquote>The compiler warns "Cast from '[CALayer]' to unrelated type 'CAShapeLayer' always fails"<div><br></div><div>So it looks like $0 is the array itself. <br><div><br clear="all"><div>This works: </div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>let layers = myView.layer.sublayers?.filter({ $0 is CAShapeLayer }).map({ $0 as? CAShapeLayer }) <br></div></div></blockquote><div><div><br></div><div>But I thought FlatMap should do it in a single step.</div><div><br></div>-- <br><div>Nate Birkholz</div>
</div></div></div>