SwiftUI / Xcode Error - Updating took more than 5 seconds - xcode

When I try to preview one of my views in the canvas I keep getting the following error:
PreviewUpdateTimedOutError: Updating took more than 5 seconds
All my other views load perfectly fine.
Why is this happening and how do I resolve?
I am using SwiftUI in Xcode 11.4 (public release)

I stopped using the simulator and chose "Any iOS Device" and that solved the problem.

In my case the issue was this line in Build settings:
Something I did accidentally changed signing settings in my project. Specifically, "signing identity" was set to "Sign to Run Locally.".
For some reasons, SwiftUI Previews don't work then.
Simply deleting this line from build settings (aka setting default value) solved the problem.

Some time, the error displaying is not the real error.
For me it was because i missing : .environmentObject(...)

As of Xcode 12.5.1, the message PreviewUpdateTimedOutError: Updating took more than 5 seconds most likely means that your app crashed and thus updating the preview failed. The real reason for the crash is unfortunately obscured by this useless message (why Apple would do that is beyond me). To get at the real reason, you'll need to:
click Diagnostics at the top of the preview next to the useless error message
in the next dialog, click Generate Report > Reveal in Finder
This will take a bit. Then Finder will open with a folder highlighted. Open that folder. Inside you'll see a lot of log files and folders.
If your app indeed crashed, you'll see a folder called CrashLogs which contains crash logs for your app, including the error message and stack trace. This should help you resolve the actual error causing the preview to break.
Note that for me, sometimes the CrashLogs were not included in the report even though my app really did crash. Retrying the preview and generating another report fixed this for me. The whole error reporting process seems to be rather unstable for the previews, unfortunately.

Try Clean (Shift + ⌘ + K) and Build (⌘ + B) to build again the SwiftUI project, it works in Xcode 11.6. Try building a basic hello world app.

In my case the issue was that the PreviewProvider was marked private. Simply make it internal or remove the private access modifier.
private /* <- remove */ struct YourView_Previews: PreviewProvider {
static var previews: some View {
// Your previews
}
}

I am using Version 13.2.1 (13C100). I have Clean (Shift + ⌘ + K) and Build (⌘ + B) the project. But, the problem remains.
Then, just restarted Xcode. And the problem gone.

In my case viewModel required to display SwiftUI_preview was doing a call to a CoreData (fast call) in the init of the viewModel.
Moved actual call of that "reload() method" so it's not called on preview, fixed.
(I believe the correct way is to use mocked protocol instead of instance of the viewModel)

If you have an .onAppear clause, try commenting that out for preview.

None of these suggestions helped me but I did discover that you can't rely entirely on a successful build to pick up all issues. In my case I had '.modifier(modifier:)' entered incorrectly as 'modifier(modifier:)'. My code built successfully but my preview did not work until I added the period before modifier.

For me the issue was related to a force unwrapping of an element not being found at preview time.
Note: Always check the diagnostics report. The issue will be at the top section after termination reason.

In my case the canvas/screen size was smaller than the content, so simply wrapping my content in the scrollView do remove the error and displaying the content in the canvas.

I had a fatalError("...") in my code, which I only figured out after reading the diagnostic logs. Would be nice if SwiftUI actually hinted this!
You can get the diagnostics by clicking "Diagnostics" next to "Try Again" at the top of the preview window.
To summarise lots of answers here, it seems that the preview taking a while to update is the equivalent of a crash, when running on a real device or on the simulator.

First comment out all the environment Objects are used for the particular View. Once you get preview then uncomment it to run the build. This trick works for me
//#EnvironmentObject var observerObj:PropertyObserver

I had this issue as well, and nothing fixed the problem. I am now on 11.6 and after updating the issue went away. I think it might be a problem with Xcode 11.4.
I'd suggest updating Xcode if possible.

In SwiftUI, you couldn't add more than 10 subviews into your contentview, otherwise it couldn't compile.

I had the same problem, then I started to comment out the subViews inside my main view, one by one & try to preview again then I found out the problem was caused because I forgot to put a dot before one of the subViews attributes.
So that's how I fixed it.

The reason is because its unable to find the landmarkData.json file. To resolve this,
select landmark.json file in Resources.
Show Inspectors ( top right icon )
Select show file inspector
Under Target membership, select / check Landmarks
This should resolve the preview issue.

For some reason, in SwiftUI, when I embeded Text in Scroll View and VStack, this error occurred. After few unsuccessful attempts to fix this by clearing and building project, I deleted code and wrote it down again, same as it was. Now it is working.

I had my run device set to a real device I use for testing. When I changed that to one in the simulator it started working again.

Similar to #YannSteph, this happened to me because I put the .environmentObject() at the app entry point where it creates the first view:
#main
struct RecipeApp: App {
var body: some Scene {
WindowGroup {
RecipeTabView()
.environmentObject(RecipeModel())
}
}
}
But this prevented the preview from working. I thought I was being smart putting it there, so all the views could have access to it, but it just crashed the preview.
Moving it back into the main View.Swift file that is my app's starting view fixed the preview issue.
^^^
EDIT: Ran into this again when I didn't put the .environmentObject() in the struct for the preview. Probably a rookie mistake but there appears to be many ways to trigger this error.

I had the same issue after creating a brand new Multiplatform App project using Xcode 12.5. Based on the solutions above I followed a hunch and now believe that the issue is due to invalid path parameters.
After renaming the Schemes and Targets from (iOS) to .iOS (and the same for macOS), to remove spaces and brackets, it is now working.

I had this issue after changing bundle id and signing from personal to team.
After changing device to Any device as advised here, I received another error description, saying
Could not install the preview host "AppName.app" on iPhone 12 Pro Max
agentBundle = com.bundle.Its.AppName {
url: file:///Users/macbookair/Library/Developer/Xcode/DerivedData/AppName-> desupjbpqvjlegfbskxydixpouvc/Build/Intermediates.noindex/Previews/AppName/Prod> ucts/Debug-iphonesimulator/AppName.app
> version: 49557
signingInformation: Code Signing {
identifier: com.bundle.AppName
hasGetTaskAllow: false
isSandboxed: false
}
}
Clean build, deleting Derived, Deleting all apps installed on simulators, cleaning Xcode Cache, restarting Xcode and Mac didn't help.
What had helped was creating new project with initially correct bundle id and copying all my files there.

I have got into the same issue on Xcode 12.4, but the code works fine on Xcode 13.0.

I was following the IOS App Dev Tutorial, where one creates an app named ScrumDinger. I ran into this issue at Displaying Data in List
In my case the problem was that I wrote in CardView.swift
HStack {
Label("\(scrum.attendees.count)", systemImage: "person.3")
accessibilityLabel("\(scrum.attendees.count) attendees")
instead of
HStack {
Label("\(scrum.attendees.count)", systemImage: "person.3")
.accessibilityLabel("\(scrum.attendees.count) attendees")
The missing dot before accessibilityLabel was the problem.
Tutorial:
https://developer.apple.com/tutorials/app-dev-training/displaying-data-in-a-list

In my case the issue was that I was trying to preview a view with a fixed width (.previewLayout(.fixed(width: 344, height: 220))) wider than the selected simulator (iPhone SE 1st generation) 😬

I get this error often. My last time of occurrence, I had "gesture" instead of ".gesture". Usually its best to just need to find the error in your code yourself because Xcode does not point out the issue directly.

I only had Xcode 14 Beta installed on my machine and the previews did not work. All of the other answers did not work for me.
Installing Xcode 13.4.1 and running the preview with it did solve my problems and now I can also see the preview in Xcode 14 Beta as well.

In my case, I disabled automatic canvas refresh by going to Editor -> Canvas -> Automatically Refresh Canvas and making sure it.
Then I use βŒ₯⌘P (Command-Option-P) to refresh the canvas preview.

Related

FileProviderExtension won't be loaded in macOS 12.2

I am new to macOS development.
I am trying to develop macOS FileProvider extension, and everything was fine until I updated my macOS from 11 to 12.2.
After updating OS, FileProvider extension won't being loaded by NSFileProviderManager.add(domain) and its completion handler returns error - NSFileProviderDomain.Error.providerNotFound
#IBAction func tapAddDomainButton(_ sender: Any) {
NSFileProviderManager.add(domain) { error in
print("Error: \(error)") // <- Error: Optional(Error Domain=NSFileProviderErrorDomain Code=-2001 "The application cannot be used right now." UserInfo={NSLocalizedDescription=The application cannot be used right now.})
}
}
I've made a new boilerplate project with default macOS > App + 'File Provider Extension' in Xcode, and still got same error.
Same code works on macOS 11.6.1.
Weird thing is that apple sample code won't return error and still works in macOS 12.2.
I can't find any difference between my code and Apple Sample Code.
I uploaded my test project here.
Please help
Thanks in advance.
Additional info: My colleague tested in macOS 12.0.1/12.1 and my test project works fine.
I encountered the same problem and even opened feedback with apple.
What I figured out (after way too long pulling my hair out) is, as you write, the app group is essential.
But not only that, the Extension Info.plist key "NSExtensionFileProviderDocumentGroup" must correspond to your app group.
I think I managed to this problem.
The key point is AppGroup. FileProvider requires AppGroup capabilities.
I think that a step to reproduce the issue likes below.
Launch provider without AppGroup at first time, and face the FileProvider error.
Add AppGroup capabilities and relaunch.
Still got the error.
New project with adding AppGroup capabilities at first launch won't fail.
I managed to fix it by changing the app and extension group (com.apple.security.application-groups):
From $(APP_TEAM_ID).MyGroup
To group.MyGroup

Prevent or clear app state persistence for MacOS SwiftUI Document Based App

I am developing a MacOS Document based app using SwitfUI on MacOS 12.0.1 using Xcode 13.1 on a MacbookPro M1 Pro. I am encountering an issue that the app is always re-opening the document browser at the last used directory. Which is OK when it is on the Machine but a pain if the last used was on a network drive. I am trying to find a way of suppressing this "always restore using the last directory" mode of operation.
I have tried using the #NSApplicationDelegateAdaptor approach and implementing;
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
print(#function + " returning false")
return false
}
within my NSApplicationDelegate class, which does get called (although it seems sometimes after the dialog is presented), however this does not stop the app secretly remembering the last directory.
Does any know where this information might be being hidden or if it can be suppressed ?
I have looked for, but cannot find, a way of injecting a starting directory into a DocumentGroup as a possible solution.
TIA Alan.
Ok, for anyone who ends up here looking for a similar issue.
After a chunk of digging I found the answer, for me, was to add
UserDefaults.standard.removeObject(forKey: "NSNavLastRootDirectory")
into the app startup. It was also suggested to do
UserDefaults.standard.removeObject(forKey: "NSNavLastCurrentDirectory")
However, just doing the first appears to suppress the file open dialog, doing both causes the file open dialog to open with the user Documents directory.

Xcode 13 will not show Preview

I have a brand new 21 Macbook Pro with the M1 Pro chip. I installed Xcode from the app store, and I have also installed Xcode beta. I am completely up to date on Monterey as well.
I am building a swift UI app and I cannot get preview to work at all.
I get the following error.
== PREVIEW UPDATE ERROR:
MessageSendFailure: Message send failure for send previewInstances message to agent
==================================
| RemoteHumanReadableError
|
| LoadingError: failed to load library at path "/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib": Optional(dlopen(/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib, 0x0002): tried: '/Users/brandon/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Products/Debug-iphonesimulator/SwiftUIView.2.preview-thunk.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib' (no such file), '/Users/user/Library/Developer/Xcode/DerivedData/Test-gfnknimtrrhvztavjffxvzjvrvmo/Build/Intermediates.noindex/Previews/Test/Intermediates.noindex/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/arm64/SwiftUIView.2.preview-thunk.dylib' (no such file), '/usr/lib/SwiftUIView.2.preview-thunk.dylib' (no such file))
I have tried to reinstall xcode, reboot you name it.
I can get simulator to work...
Any ideas?
Nothing I tried worked, including running:
sudo xcodebuild -license in the terminal
Deleting derived data
Sign in again to GitHub
Restarts
Only when I toggled Automatically refresh canvas (Editor > Canvas) I got preview back.
Preview was failing on a new default projects as well.
I had the same problem and found a solution here:
https://developer.apple.com/forums/thread/691237
I was not signed in to GitHub so as suspected, it does not play a role.
It seems Xcode got in to an invalid state. I suspect that simply disabling and enabling automatic signing would resolve the issue but I also cleared the Container folder for my project as suggested in the post.
Same issue and resolved it by change Mac's user name to lowercase.
Username->username
I had the same problem because I downloaded a GitHub project (an existing SwiftUI project) and I didn't create a new SwiftUI project from scratch. I notice the SwiftUI view doesn't had the PreviewProvider struct at the bottom:
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView()
}
}
After adding the PreviewProvider struct, Xcode showed the Preview.

Class PLBuildVersion is implemented in both frameworks

iOS 10 / Xcode 8 GM build getting the below, never had it before on Xcode 7. Any ideas?
objc[25161]: Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x12049a910) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x1202c4210). One of the two will be used. Which one is undefined.
(NOTE: Only seems to happen in simulator, does not appear on real device).
Main Idea
Main idea is simple:
If your app (or dependencies, such as Pods) uses framework, that uses explicit (or implicit) PhotoLibraryServices.framework or AssetsLibraryServices.framework as dependency, Xcode warns you (even if you are using only one of them). It might be Photos/PhotosUI.framework or AssetsLibrary.framework, or another (I don't have full list of dependencies, but it is possible).
What is the problem?
Class with name PLBuildVersion is defined in both PhotoLibraryServices.framework and AssetsLibraryServices.framework. Class name is unique in Objective-C (you can't define 2 classes with same name), so it is undefined which one will be used in runtime.
However, I think that it will not be a problem, because both classes have same methods and fields (checked this with disassembler) and I guess that both were compiled from the same source.
Radar is already sent.
As per answer from Apple employee on Apple's Developer Forum:
You don't control either of the class sources listed, so there isn't anything you can or should do – aside from Reporting a Bug.
I was unable to find a way to get rid of the warning, but if you want to prevent the app from crashing, you need to provide a description for why you are accessing the camera, photo library, etc. This is new in iOS10.
Input the following into your Info.plist file.
Photo
Key: Privacy - Photo Library Usage Description
Value: $(PRODUCT_NAME) photo use
Camera
Key: Privacy - Camera Usage Description
Value: $(PRODUCT_NAME) camera use
More info can be found here: https://iosdevcenters.blogspot.com/2016/09/infoplist-privacy-settings-in-ios-10.html
I find you can get this error merely by using a UIWebView. My solution was to replace my use of UIWebView with WKWebView.
I had this after adding Answers on Fabric to my project.
Deleting derived data did the trick for me. (shift alt command k in XCode)
Edit a year later:
After deleting derived data, always exit XCode and start it again.
In unrelated cases I have the impression that deleting derived data does not clear XCode’s in memory caches of the derived data.
Resetting the iOS simulator fixed this for me. Simulator -> Reset Content And Settings.
In my case this warning started to appear after opening a second xcode project and running the second app on the simulator. After changing back to the first app, the warning started to appear. I just quit the Simulator and Xcode and reopened my project. The warning disappeared after that. If that doesn't solve it, proceed with the other answers. Xcode can be really picky sometimes.

Unable to process application Info.plist validation at this time due to a general / IO error [duplicate]

I am creating a newsstand application. the application is ready, now i am trying to upload the app in apple store using Application Loader. While uploading the zip file its showing the error message as
Unable to process application info.plist validation at this time due to a general error (1095)
I googled this in the net, but did not find the solution still.
This is clearly an Apple server issue, not an Xcode/iOS/OSX issue. Just wait patiently and Apple's servers will catch up to the traffic, or solve whatever issues they're having at their end.
If you're anxious, feel free to just sit there and restart Xcode until it works - but it's not restarting Xcode, only the time you waste that's solving the issue.
While you're waiting, run your apps in Instruments and solve some performance issues ;)
I just had this error. I waited an hour and tried again with the exact same build and it was all good. Vote for it being Apple's temporary glitch.
I had the same problem. I closed Xcode, restart my computer and it worked.
One possible problem to this is corrupted png files. The png files should not be interlaced
I found a solution to the problem.
If you're using Xcode 4+, you don't have to use Application Loader anymore. Instead you should archive your project in Xcode (Product->Archive). It will then open the organizer, where 3 buttons are displayed. Hit the submit button.
If you've created an entry for your app with Itunes Connect, you should be able to choose that from the list, and then select your distribution profile. Then hit the next button, and you should get a message, that tells you, that your app has been submitted.
At least that worked for me.
Use Application Loader.
I'm getting this a lot today.
Application Loader worked.
XCode > Project > Archive
XCode > Organizer > Distribute > Enterprise/add Hoc > Save As
Saves as YOURAPP.ipa.
Make sure Save for Enterprise Deploy remains UNCHECKED.
Download latest Application Loader.
tap 'Deliver Your App'
make sure new version in itunes connect in WAITING FOR UPLOAD state
Click on Activity... button
TIP: open Console.app to see XCode Validation errors
Click on ALL MESSAGE on list of logs on right.
Then in search enter 'XCode' or 'Application Loader'
to monitor any errors with your upload.
Note:
I did all this and still got email about missing 120x120 icons.
Forgot to update them in Build Target > General Tab
List of new icon requirements for iOS7
http://www.icenium.com/resources/forums/icenium-general-discussion/missing-recommended-icon-file
Another reason why this can happen is the duplicate product name. Despite your app names, executable names, display names or bundle IDs are different, if the product name exists in your current apps this error is gonna occur.
"The server returned an invalid response. This may indicate that a network proxy is interfering with communication, or that Apple servers are having issues. Please try your request again later.""
Reset The internet connection.
Reopen the xcode.
Set the profile again.
Clean build.
And Archive the build.
Works perfect for me (With in 5 minutes no need to wait).
Thanks
It's just the time, because you can't control Apple's Server's traffic problem, We all merely become the victim of that..So cut the long story short...
By restarting XCODE may work but everyone as in my case, i tried by restarting XCODE, SYSTEM, ROUTER and anything and everything possible, only error name had changed from "The network connection was lost" to "The request timed out" and vice Versa..!
Just think at what time less people would be accessing the sever...
PS: Only perseverance can help you in this way..keep redialing..And WAIT and WATCH:P
I solved ... :)
Please remove all your icons and splash image also remove icon Files and icons File( IOS 5 ) from info.plist and then add all your icons to app bundle ...
After this update info.plist iconFiles field add desired name of icons....
And last but not least remove Provisioning profile from developer portal and recreate it ...
Clean your build and Archive it and using Application Loader submit it to AppStore ...
it work for me and i think it may help you...
Not every time not it is Apple server issue,sometime we did some bad linking according to me :)

Resources