13

Trying to integrate SwiftUI into an large existing project. I have followed steps to integrate this into my project, but when I try to preview my new SwiftUI view file, I get the error..

Cannot preview in this file - current target needs adjusted build settings

There is a little (i) symbol at the end which states..

"project.app" needs -Onone Swift optimization level to use previews

I have added my Scene delegate though the SwiftUI file is not the root view controller so I made careful attention of leaving willConnectTo method empty.

By default under my Project < Build Settings < Swift Compiler - Code Generation < Optimization Level.. Debug is set to No Optimization[-Onone], release is Optimize for Speed[-O]... This is the same settings as my practice SwiftUI project.

I have tried a number of solutions but nothing has worked yet.

Reviewing the license agreement in the terminal

Checking my Command Line Tools

Edit my Info.plist - Though this didn't solve it, it seems like this was something important to do.

Ultimate Explanation For Integration that I followed

C. Skjerdal
  • 2,750
  • 3
  • 25
  • 50
  • 1
    Well not proud of this, but I found one spot that targeted iOS 13.0, and another ios 13.1.. please let me know if I should delete this, mind you these links are quite helpful for converting an old project to Swift UI – C. Skjerdal Jan 23 '20 at 02:08

2 Answers2

34

Ensuring the Debug config is chosen in Product -> Scheme -> Edit Scheme -> Build Configuration helped me to solve the issue.

Shengchalover
  • 614
  • 5
  • 10
0

Setting both Optimization level to : ✓ No optimization (-Onone) worked for me.

See resolution ▶︎: https://i.stack.imgur.com/Li6vp.png

BugDoctor
  • 39
  • 4