问题
I'm writing a UIView subclass that uses both IBInspectable and IBDesignable. I'm not doing anything unusual, but my subclass causes Xcode 6.2 to endlessly rebuild the project. My Identity Inspector shows this state oscillation under the heading 'Designables':
Every time the build restarts, the inspector loses focus. This makes it hard to edit anything from IB, which defeats the purpose of writing this class in the first place.
Here is the implementation of my DesignableTestView:
import UIKit
@IBDesignable class DesignableTestView: UIView {
@IBInspectable var testBackground:UIColor? {
didSet {
if testBackground != nil {
self.backgroundColor = testBackground
}
}
}
}
Is there any way to change my code or settings of Xcode to prevent the constant rebuilding?
回答1:
I'm wonder if this designable view class is part of the current target. In WWDC 2014 video What's New in Interface Builder, in the Live Views demonstration, they describe that the first step is to ensure that the designable class is in a separate custom framework target. That video demonstrates the process for creating this custom framework target within the project.
If that's not issue. I'd suggest cleaning your project ("Clean" on "Product" menu) and rebuilding just the custom framework target to make sure that's ok before you try doing anything in IB, itself. Bottom line, make sure that the framework can be built without incident. If the problem still persists after doing that, I'd take it to the next level and (a) find the Xcode derived data folder; (b) quit Xcode; (c) clear the derived data folder, (d) restart Xcode, and (e) trying building the framework target again.
回答2:
I was still having this issue (in Xcode 8.3.3) even after moving my IBDesignable classes into a separate framework. What worked for me was to open the offending Xib file, uncheck Editor > Automatically Refresh Views, and then restart Xcode.
回答3:
I was ALSO still having this issue Xcode 9.3 even after moving all IBDesignables and IBInspectables to a separate framework (and clean all, kill derived data). IB would continue to rebuild the main target and its dependencies.
The solution I found here https://www.e-learn.cn/content/wangluowenzhang/307740 solved it:
- remove all
@IBDesignable
and@IBInspectable
- clean all, clear derived data, close Xcode
- reopen Xcode, force IB to rebuild with no IBDesignables (Editor -> RefreshAllViews should be greyed out not)
- close Xcode
- add all
@IBDesignable
and@IBInspectable
back - reopen Xcode
- RefreshAllViews should be available, click it.
- voila, IB never only rebuilds framework from now on
Clearly there was something funky cached in Xcode that cleanall/killing derived data didn't wipe.
来源:https://stackoverflow.com/questions/29260077/ibdesignable-view-causes-endless-rebuilding