UIVisualEffectContentView.contentView.addSubview not working in Swift Playground

UIVisualEffectContentView.contentView.addSubview appears to be actually trying to add the sub view to the parent UIVisualEffectView in Swift Playgrounds. Code that works fine in an actual iOS app causes Swift Playgrounds to produce error: "Do not add subviews directly to the visual effect view itself, instead add them to the -contentView." Except that is exactly what the code is doing "blur.contentView.addSubview(vib)" So the internal implementation in Swift Playgrounds must be doing something wrong. Again the same code works fine in an iOS app.

  • Sorry "UIVisualEffectContentView.contentView.addSubview" above should read "UIVisualEffectView.contentView.addSubview" but the point is the same.

  • Somehow this fixes it:

    (blur.contentView as! UIView).addSubview(vib) (vib.contentView as! UIView).addSubview(lab)

Add a Comment