Xcode 13.2.1 (13C100) Preview Not Working but Simulator Works!

For the last 3days, I'm completely stopped my work because my Xcode got an unknown issue. I did several things like delete Xcode, new install Xcode, restore from backup nothing make any change! Currently, the project is built and run in the simulator but not in the preview window it gives a message:

Cannot preview in this file - Timed out waiting for connection to DTServiceHub after 15.0 seconds.

iMac becomes very slow. Please Help!

Answered by GridPen in 704765022

Good News

I have also tried a fresh OSX installation but the issue has not gone at all. Suddenly It fixed, maybe the last update from apple through a software update called "Command Line Tools for Xcode". Thanks to all of the Apple Devs and Frameworks Engineer who is tracking down the issue with me.

Could you post the code, not only a screen shot, so that we can test without having to retype everything ?

I tested this code with Xcode 13.2.1. It runs perfectly. Which version of Xcode ? Did you inspect the disgnostics ?

let columns: [GridItem] = [GridItem(.flexible()),
                           GridItem(.flexible()),
                           GridItem(.flexible())]

struct ContentView: View {
    
    var body: some View {
        LazyVGrid(columns: columns) {
            ForEach(0..<9) { i in
                ZStack {
                    Circle()
                        .foregroundColor(.red)
                        .opacity(3)
                }
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
     
          ContentView()
  }
   
}

Here is screenshot (only difference is ContentView17 vs ContentView).

Thanks for your quick reply 👋, I try to run your given code idea still nothing changes!

Which version of Xcode ?

My Xcode Version 13.2.1 (13C100)

Did you inspect the disgnostics ?

Yes! The window message says- TimeoutError: Timed out waiting for connection to DTServiceHub after 15.0 seconds. so I generate the report check attachment.

Please take a look. Regards!

You have some temp files that cannot be deleted.

I would try:

  • first to do the usual clean build folder and try again
  • if not enough, quit Xcode, reboot Mac and restart Xcode
  • If still not enough, create a new project and copy the content of each file, file by file (that's easy with SwiftUI as there is no links to storyboard).

There is an advice to change permissions for '/var/folders/bb/4bw6qxl10q5b94qzc8yjv6jc0000gn/T/previews-diagnostics-20220106-180743/simctl_diagnose', but I'm not sure you will find it easily in Finder.

I see in another post (https://developers.apple.com/forums/thread/697748) that you are not alone with this problem. I'm on MacOS 11.6, not 12.1, so Monterrey could be the reason. You filed a bug report, you were right. Keep us informed if you get some answer there

Hi,

Sorry to hear you are having problems getting previews working. This sounds like an issue we are already tracking, but to be sure we'd need the full diagnostics from you. To file a feedback with diagnostics:

  1. When you get an error in Xcode Previews, an error banner appears in the canvas
  2. Click the "Diagnostics" button in that banner
  3. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  4. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)

I am having the same problem ever since updating Xcode yesterday. Here's my diagnostics screen:




----------------------------------------



CompileDylibError: Failed to build ContentView.swift



Compiling failed: file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/Visibility.h' has been modified since the module file '/var/folders/jt/s96c8fv518s_1y_6925ml4sc0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm' was built: mtime changed



<unknown>:0: error: file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/Visibility.h' has been modified since the module file '/var/folders/jt/s96c8fv518s_1y_6925ml4sc0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm' was built: mtime changed

<unknown>:0: note: please rebuild precompiled header '/var/folders/jt/s96c8fv518s_1y_6925ml4sc0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm'

<module-includes>:1:9: note: in file included from <module-includes>:1:

#import "LibcOverlayShims.h"

        ^

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/LibcOverlayShims.h:21:2: error: file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/Visibility.h' has been modified since the module file '/var/folders/jt/s96c8fv518s_1y_6925ml4sc0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm' was built: mtime changed

#include "Visibility.h"

 ^

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift/shims/LibcOverlayShims.h:21:2: note: please rebuild precompiled header '/var/folders/jt/s96c8fv518s_1y_6925ml4sc0000gn/C/clang/ModuleCache/108X1IN8WGNX1/SwiftShims-2TTN5UXQBRCCQ.pcm'

#include "Visibility.h"

 ^

<unknown>:0: error: missing required module 'SwiftOverlayShims'





==================================



|  BuildInvocationError

|  

|  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -F /Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator -enforce-exclusivity=checked -DDEBUG -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -target arm64-apple-ios14.0-simulator -Xfrontend -serialize-debugging-options -enable-testing -swift-version 5 -I /Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Products/Debug-iphonesimulator -F /Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Products/Debug-iphonesimulator -c -j8 -serialize-diagnostics -Xcc -I/Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/CAI-generated-files.hmap -Xcc -I/Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/CAI-own-target-headers.hmap -Xcc -I/Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/CAI-all-target-headers.hmap -Xcc -iquote -Xcc /Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/CAI-project-headers.hmap -Xcc -I/Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Products/Debug-iphonesimulator/include -Xcc -I/Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/DerivedSources-normal/arm64 -Xcc -I/Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/DerivedSources/arm64 -Xcc -I/Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/DerivedSources -Xcc -DDEBUG=1 -working-directory "/Users/danuff/Documents/CPS/iOS/iOS 15/Projects (Current)/iPhone : iPad/SwiftUI/General/CAI" /Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/Objects-normal/arm64/ContentView.1.preview-thunk.swift -o /Users/danuff/Library/Developer/Xcode/DerivedData/CAI-fpvdurwckhlgpoczgdolkzdvwcyr/Build/Intermediates.noindex/Previews/CAI/Intermediates.noindex/CAI.build/Debug-iphonesimulator/CAI.build/Objects-normal/arm64/ContentView.1.preview-thunk.o -module-name CAI_PreviewReplacement_ContentView_1 -Onone -Xfrontend -disable-modules-validate-system-headers -gline-tables-only
Accepted Answer

Good News

I have also tried a fresh OSX installation but the issue has not gone at all. Suddenly It fixed, maybe the last update from apple through a software update called "Command Line Tools for Xcode". Thanks to all of the Apple Devs and Frameworks Engineer who is tracking down the issue with me.

Xcode 13.2.1 (13C100) Preview Not Working but Simulator Works!
 
 
Q