I have the bellow line of code which is meant to prevent a problem where a sublayer is displayed over another posts content. The method in which this line is excited is called at the time of the user exiting a post.
newBaseP3FolderLayer.layer.sublayers?.remove(at: 1)
But now, I think as a result of this code, there are instances where another video will all of a sudden cover all other images.
I noticed that this only happens when the number of subLayers is 14. (This also may be true for numbers above this) while printing the number of sublayers when leaving a post I noticed that the code worked fine (for vals like 10 or 11 and 12) until the number of subviews went to 14.
How can I fix this?
This would be better approach
for sublayer in sublayers {
if sublayer.name == "yourLayerName" {
sublayer.removeFromSuperlayer()
}
}