IBDesignable UIView Subclass Always Fails to Render in Interface Builder
Asked Answered
E

1

5

I see a number of questions about this, but few answers (one answer solved a previous similar issue, but not this one).

THE PROBLEM

I have an IBDesignable class. It derives from UIControl, but the same thing happens if I derive from UIView.

It basically looks like this:

@IBDesignable
open class RVS_Checkbox: UIControl { ... }

It works just fine (the link leads to this project, which is a "drop-in" UIControl class).

But it won't render in Interface Builder. I get this error:

The error I get

Here is the error, verbatim:

The built product "/Volumes/Development/Developer/Xcode/DerivedData/RVS_Checkbox-ficjiiqrddckmjenmsrbrxvihaky/Build/Intermediates.noindex/IBDesignables/Products/Debug-appletvsimulator/RVS_Checkbox" does not exist in the file system. Make sure your built products contains either an application or a framework product.

First of all, this is a tvOS error, and this is an iOS-only class. I had a similar issue before, and this answer solved that for me. I wrapped the code in the #if...#else...#endif, like so:

#if os(iOS)
    @IBDesignable
    open class RVS_Checkbox: UIControl { ... }
#else
    @IBDesignable
    class RVS_Checkbox: UIView { }
#endif

I even gave it an empty "placeholder," in case it needed to be held.

No dice. Whatever I do, the IB error still happens, and the element doesn't render.

Like I said, it still works fine, and also displays the proper inspectable properties:

Inspectables

but it won't render.

Here's the error, next to the directory it's complaining about:

Error and Finder Window

I am sure that I'm doing something wrong, but have no idea what. I tried deleting DerivedData, cleaning the project, tried all 4 of my targets, etc.

No dice.

Any ideas?

Erb answered 21/3, 2021 at 19:34 Comment(3)
It's beginning to look like this may be an issue with Xcode 12, and it won't be solved until I finally get an M1X/M2 Mac, later this year. Most of the talk I've seen about this problem points that way (and I have yet to see any real solutions). It's not that serious.Erb
Well...the tumbleweds are strong, in this one. I sent up a DTS request (I never use them, so why not?).Erb
It's looking increasingly like this is an issue with Xcode, and Apple isn't in much of a hurry to address it. It seems to be connected with the complexity of the IB file. I can't get it to happen with simple projects, but as soon as it starts getting complicated, I get the error. May not be worth it for me to try to investigate further.Erb
E
6

OK. I figured it out. It's a bug in Xcode. I submitted a report.

If I open the project on the internal drive, the control renders, no problem.

If I open the project on an external drive, it fails to render.

Very strange, but I was able to reproduce it 100% of the time, using a very simple project.

I suspect that most developers simply get Macs with big internal disks, and do their development on these. I had to get one with a limited internal drive, so I use one of those SanDisk screamers as an external for my development.

I wonder what other issues I may be encountering? I find Xcode to be quite buggy.

UPDATE: I am attaching the two screengrabs used in the bug report.

This demonstrates the setup. I am using the same exact project, in two different places on my system. The one on the left is on the internal MacBook Pro drive, and the one on the right is THE SAME EXACT PROJECT, but on an external drive.

This link downloads the project, in a zip file.

The directory setup

The failure

Erb answered 26/3, 2021 at 14:33 Comment(6)
Thanks for the follow up unfortunately not a fix in my case. I am facing the exact same issue except mine has always been on the local / internal disk. My class is wrapped in the #if os(iOS) check but still getting the tvOS error in IB.Palestrina
I think this whole thing is a bug farm. Unfortunately, I don't think Apple is particularly interested in addressing the issue. They are going all-in on SwiftUI (which is still not ready for some of the more ambitious projects).Erb
This still not working for SPM, in your example project you have 2 targets - direct and spm, but 'spm' not rendering designables when you remove 'direct' source codeAntenatal
Not surprised. I have heard SPM doesn’t play well with designables.Erb
You just saved me some days. I have a mac with 64Gb RAM, so I decided that Intermediates will go to RAMdrive, and made a symlinks from ~/Library/Developer/XCode/{Archives,DerivedData} to the directories on the ram drive. And because of that I received "the built product does not exist in the file system" error while rendering IBDesignable from github.com/letatas/ReusableXibViews . After I have changed the derived data path in XCode to be on the RAMdrive directly, it just worked!Jordanjordana
@apollov, glad it helped. It's sad that this is still an issue, after all this time, but I have a feeling that Xcode is a monster that can no longer be controlled. monkeyuser.com/2022/business-careErb

© 2022 - 2024 — McMap. All rights reserved.