Reputation: 509
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?
Upvotes: 21
Views: 6108
Reputation: 437402
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.
Edit:
Above link seems to be dead. Video can be downloaded directly from: http://devstreaming.apple.com/videos/wwdc/2014/411xx0xo98zzoor/411/411_hd_whats_new_in_interface_builder.mov?dl=1
There is also a github gist with links to all the 2014 material: https://gist.github.com/jianpx/eea1e938d5868e980b11
Upvotes: 17
Reputation: 1718
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:
@IBDesignable
and @IBInspectable
@IBDesignable
and @IBInspectable
backClearly there was something funky cached in Xcode that cleanall/killing derived data didn't wipe.
Upvotes: 1
Reputation: 305
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.
Upvotes: 9