<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&#39;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 &quot;Cast from &#39;[CALayer]&#39; to unrelated type &#39;CAShapeLayer&#39; always fails&quot;<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>