SwiftUI Preview timeout for large project - ios

I've been trying to preview SwiftUI files in my large iOS project and cannot get past this error TimeoutError: Timed out waiting for a thunk to build after 30.0 seconds.
What's interesting/confusing is that a newly created SwiftUI file with the default "Hello World" Text does successfully load the preview in the same project, however more complex SwiftUI files show the time out error even when I change the preview struct to display a Text("Hello World") view.
Has anyone else experienced this or could point in what direction I can dig to fix this timeout issue?

In case it helps someone else... I ended being able to load the previews by temporarily setting the project to iOS 13 development target (normally it's iOS 12). Thankfully we'll be dropping iOS 12 soon so this won't be an issue after that.

I just fixed it on my project after leaving it be for several days cause I couldn't figure out.
So as the log mentionned, I had to "break down" my View code in smaller chunks. First identify where in the view does the compiler complain by commenting parts of it. Then when you identified the piece of code that's causing the issue create new separate views from it and call them in place of the big chunk. From my part I had a List row made of an HStack wich contained a Text and Textfield. The compiler didn't like that at all. I just put the HStack in a new view and called it in the same place and problem solved.

Related

SwiftUI Crash LayoutComputer.EngineDelegate.sizeThatFits?

I can't identify the source of this crash, and when I "Open in Project" Xcode doesn't point to any particular area of my code. What could be causing this? It seems to be when a certain button is tapped.
Solution
After I ran into this same sort of problem, the solution for me, was to clean my build folder, then perform a full build of my application for my target device, as opposed to not cleaning my build folder, and just performing an incremental build of my app.
Steps I followed to trigger this bug, and to resolve my issue
I had an Xcode Project, containing:
A Swift Package I'd added as a "Local Swift Package" which contained:
A module that defined a public method (let's call it modifyListRow) in an extension of the View protocol.
My SwiftUI Application for iOS which contained:
My #main App which rendered a SwiftUI View that contained:
List { ForEach { MyRow.modifyListRow() } }
I then did a full build & run of my app - which depended on that Local Swift Package, and after the app launched on my physical iPhone X device, I saw that everything worked properly.
I then modified the body of the modifyListRow method, in such a way that it would affect how the sizes of the List-rows produced by the ForEach View should be calculated by the SwiftUI Framework.
I then did an incremental build and run of my app.
This time, after my app launched on my iPhone, I just saw a blank screen in it because SwiftUI had failed to render any of my app's views, and I saw in Xcode that my app had crashed while attempting to calculate a sizeThatFits for a view - presumably for one of the List-rows produced by my ForEach View.
I then cleaned my build folder, and did a full build & run of my project, and after the app launched on my iPhone, I saw that this time everything worked properly.
Hypothesis of cause of bug for my app
Presumably, Xcode had cached the compiled code for my SwiftUI View that contained the List after I did the first full build, but didn't invalidate the compiled code for that View, despite the fact I'd modified the body of the modifyListRow method in such a way that the List-rows would have needed to have their sizes calculated differently by the SwiftUI Framework. This made it so that my SwiftUI View would not be re-compiled during the incremental build I'd performed, despite the fact the modifyListRow method was re-compiled. Consequently, the compiled code of my SwiftUI View and the modifyListRow method became "out-of-sync" in the build artefact, and hence, the SwiftUI framework failed to calculate the sizes of the List-rows. But cleaning my build folder, and performing a full-build, made it so that my SwiftUI View would be re-compiled, along with the modifyListRow method, and hence, the compiled code for my SwiftUI View and the modifyListRow method resumed being "in-sync" in the build artefact just as they originally had been. This made it so that the SwiftUI Framework would be able to successfully calculate the sizes of the List-rows.
But please remember, this is just my hypothesis as to the cause of the bug for my app - it may be incorrect.

IB Designables: Failed to render and update auto layout status - The agent crashed

I am working on an existing iOS Project in Xcode 10.2.1 on macOS 10.14.4. The uses mainly Objectiv-C but also some Swift Pods (v. 1.5.2). Recently I have also added the first Swift based ViewController using Swift 5.
The Problem:
When working on the XIB file of this Swift bases ViewController after a short time the following error message is shown in the Xcode sidebar:
IB Designables: Failed to render and update auto layout status for
ViewXYZ (abc-de-123): The agent crashed
As soon as there error occur no changes in the Interface Builder (added view, changed colors, text, etc.) are shown anymore. When I re-open the XIB file it only show grey view placeholders instead of the real content.
The problem can only be solved by re-starting Xcode but when working on the XIB again it shows up after again after just a few moment.
Things that did NOT work
Since the problem is realted to IB Designabales I checked these first. Within the ViewController I am using two different custom views which are implemented in Objective-C and marked as IB_DESIGNABLE.
These views have not been changed recently and it was never a problem to use them before. Removing all custom code from these views did not change the problem. Thus there seems to be nothing wrong with the implementation.
I found other topics dealing with similar issues, but none of the different solutions worked for me:
Re-starting the Mac, re-starting Xcode, cleaning the build folder or deleting ~/Library/Developer/Xcode/DerivedData does NOT solve the problem
Adding this code to the pod file does NOT solve the problem
Adding all UIView constructors to the views as proposed here does NOT solve the problem.
Xcode shows that the designables are up to date and does NOT offer a debug button (as shown here)
The views do not have orphant outlets
Re-creating the XIB from scratch let to the same issue
Not using the Bundle or other device specific code within the custom views did NOT solve the problem. As described before I removed ALL custom code from the classes so that they where simple UIView subclasses without any changes.
So far nothing I tried had any effect. However, most answers I found are quite old. Are there are any new proposals to solve this issue?

Swift: XPC connection interrupted and app freezes?

Ok, have no idea what is going on here but from what I understand from other questions
(XPC connection interrupted in Xcode 7 for iOS 9) , XPC connection interrupted means theres a storyboard problem. Per a similar answer I opened the storyboard as source code and looked for repeated
<keycommand>
tags, but there aren't any. I had to copy and paste a storyboard from another project since something changed, and I believe this caused it. What are my options here? What could be causing this freeze since there aren't any weird tags that I can see?
Same problem, getting the XPC error when tapping in a (SwiftUI) Text Field. Different solution:
Simulator > Device > Erase All Content and Settings
As described here,
The problem came from the keyboard that wasn't showing up. And I am not really sure why, I probably pressed a command that disables it.
To get it to work I have restarted the simulator. In the simulator menu, Hardware > Erase All Content And Settings
Now when I tap in a UITextField, the keyboard shows up and I don't get the "XPC connection interrupted" error anymore. Everything works fine.
This error was incredibly frustrating because there is no crash report, just a one-line "XPC connection interrupted" and the app freezes. And, to complicate things, it's apparently possible to get this error from some wildly differing causes -- various discussions have cases of VPN's, Bluetooth, and threading generating this. And of course -- Murphy's law -- I started getting the error after having implemented something utterly unrelated, but which has me troubleshooting threading & Core Data issues, all to no avail.
Hopefully this can help somebody else with the quick fix.
The problem for me was that there are two storyboards, the main storyboard and the launchScreen storyboard. If you go to the top left of Xcode and click on the Xcode file, it will bring you to a screen about the file. You then scroll to deployment info and switch the main interface to whichever storyboard you use. I think that since you copied and pasted the code is not linked up to the storyboard.

ios - loading decoupled view from nib file

I am having difficulty with something that seems to be trivial. I am following this project https://github.com/eppz/iOS.Blog.UIView_from_Xib and trying to implement the decoupled way of loading a view from a nib file. I was not able to get the desired result in my app (nothing shows up and I get no crashes either) so I did the following:
I took the project from Github https://github.com/eppz/iOS.Blog.UIView_from_Xib
I then proceeded to duplicate the files in the "decoupled" group and name it something trivial like "decoupled2". Basically I am creating a whole new class that stands on its own with its own nib file.
I then changed all of the internal tags and class references. Then I made sure that all of the new references were pointing to this new class.
At this point I added a 6th button to the main VC and made sure to call the right method for my new "decoupled2" class when this 6th button is pressed.
PROBLEM: Everything runs but the view from nib does not show up. Debugging view hierarchy shows nothing. Clicking the 5th button still works, so I didn't break the existing code. Why won't the newly created nib file show up?
This seems rather simple, just duplicate what already works in a project that already works and it will work...or not. What am I missing? Thank you for your help.
I have spent a few days on the problem already. Lots of research but nothing of use so far.
I re-did the task and it worked this time.
Maybe restarting Xcode 8.0 was the key or something else that is under the hood.

Xcode crash on opening storyboard

I am developing an app for iOS with Xamarin. Lately, I haven't been able to access my storyboard file in Xcode or compile my app anymore because Xcode crashes right away when opening the .storyboard file.
The error message is the following:
ASSERTION FAILURE <br>
Details: Creating an out of band arbitration unit with a view (<IBUITableViewCell: 0x7fa88d13a5d0>) as the root under another view (<IBUITableView: 0x7fa88cf000e0>) is not yet implemented.<br>The view would need to be in two arbitration units, the one above for positioning constraints, and the root of the one below for sizing constraints. <br>But then that means that subviews cannot have constraints that affect the size of the view, so the view must have ibExternalTranslatesAutoresizingMaskIntoConstraints set to YES.
<br>Object: <IBUITableViewCell: 0x7fa88d13a5d0>
<br>Method: -ibArbitrationUnitWasCreatedWithReceiverAsRootUnderParent:
I tried rebasing my storyboard to the last version that worked (the one the app was submitted to the app store) and weirdly, even that version didn't work.
My plan was to manually remove and every view controller and add them one by one to figure out where the error is.
However I don't understand why XCode crashes when opening the storyboard and not just shows me exactly where the error in my xml is.
So if anyone has encountered this problem before and has a better way to fix it than to manually do it, I would really appreciate any help.
ibExternalTranslatesAutoresizingMaskIntoConstraints needs to be YES
Sounds like the Storyboard was created with an older Xamarin.iOS that introduce this issue.
The fastest solution is to open the storyboard in vi (or Xcode / View As Source, or another text editor of your choice, and replace all translatesAutoresizingMaskIntoConstraints="NO" with "".
Save the file, re-open it in the Storyboard editor and fix your contraints.

Resources