Adding too many subviews to iPad Swift Playgrounds gives me error, “There was a problem encountered while running this playground. Check your code for mistakes”

Hi! So I’m creating my playground on iPad. Just a simple playground, not a playground book so the file, `Contents.swift` has multiple classes. However, in each ViewController class, I can add no more than 7 UIViews (including UIImageViews, UIButtons, UILabels, etc.) before my playground gives me an error: “There was a problem encountered while running this playground. Check your code for mistakes”. This is really vague and there is nothing wrong with my code. If I remove the line:

self.view.addSubview(someView)

then everything works as expected. How can I work around this?

Replies

Hi SAIK1065,


How did you determined that the error is made by adding more subviews?
There is a limit to the subviews wherein the playground crashes and that's about 45 subviews based upon my testing. Had this problem few years ago.
Just check your code, you might have missed a } or a comma.
You can also check this thread: https://forums.developer.apple.com/thread/114727
Good Luck! 🙂