0

I have an iOS app which builds and runs fine in Xcode 8 but after i updated to Xcode 9 the app throws this error at run time:

*** Terminating app due to uncaught exception ... layer = >. Do not add subviews directly to the visual effect view itself, instead add them to the -contentView.'

*** First throw call stack:
(
    0   CoreFoundation                      0x00000001114e81cb __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000110e46f41 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001114ed362 +[NSException raise:format:arguments:] + 98
    ...more stack data here...

I'm very new to iOS development and wondering if anyone has seen this recently?

EDIT (Snippet from comment):

fileprivate var _content = UIView()

internal class FrameView : UIVisualEffectView {
        internal var content: UIView {
            get { return _content }
            set {
                _content.removeFromSuperview()
                addSubview(_content)
            }
        }
    }

EDIT 2 (SOLUTION thanks to @Brandon):

fileprivate var _content = UIView()

internal class FrameView : UIVisualEffectView {
        internal var content: UIView {
            get { return _content }
            set {
                _content.removeFromSuperview()
                contentView.addSubview(_content)
            }
        }
    }
simples
  • 21
  • 3
  • This has nothing to do with Xcode 9. Since you haven't shown us your code, people here are unable to help. – Ozgur Vatansever Nov 03 '17 at 16:49
  • Instead of adding views to the `UIVisualEffectView`, add them to the `UIVisualEffectView.contentView`. https://developer.apple.com/documentation/uikit/uivisualeffectview You might be using `UIBlurEffect` somewhere in your code. Check there.. – Brandon Nov 03 '17 at 16:53
  • 4
    Your code was _always_ wrong. Now the runtime is helping you get it right. **Step one**. Read the error message. **Step two**. Do what it says. **Step three**. There is no step three. – matt Nov 03 '17 at 16:57
  • @Brandon that's a good link, i found out that my UIVisualEffectView is doing something like: internal class FrameView: UIVisualEffectView { ... internal var content: UIView { get { return _content } set { _content.removeFromSuperview() addSubview(_content) } } addSubview(_content) is actually causing the exception. But i have no idea how to fix it :)? – simples Nov 03 '17 at 17:07
  • @Brandon sorry i cannot format the code like you guys!! – simples Nov 03 '17 at 17:07
  • @matt i get that :-) but have no idea how to approach it – simples Nov 03 '17 at 17:08
  • @OzgurVatansever the code is massive, i don't know where the problem is, hence the silly question. I understand it is not Xcode 9 issue but it happens for me in Xcode 9. How would you suggest to form my questions better in future? – simples Nov 03 '17 at 17:16
  • @simples you can add the code snippet you've shared to show Brandon into your question. – Ozgur Vatansever Nov 03 '17 at 17:18
  • @matt there is no contentView in the code and i don't know where it might by. Is this a property of `UIVIew`? ( i never touched iOS so i don't know any classes in their framework ) – simples Nov 03 '17 at 17:24
  • I added your code snippet from your comment to your post. In your setter, you are doing `addSubview(_content)`.. Try doing `contentView.addSubview(_content)` and see if it behaves the same. – Brandon Nov 03 '17 at 17:24
  • **@Brandon thanks man, it works!** :+1: The exception is gone :-) @OzgurVatansever and mattt (can't add more than 2 users), appreciated your guidance and help. – simples Nov 03 '17 at 17:34
  • @matt trivial or not, but **Brandon did save me a lot of time**! Perhaps it will be useful to other (l)users like me ;). I was bashing my head around this issue for 3 days. – simples Nov 03 '17 at 17:45

0 Answers0