65

I have an Objective-C and Swift mixed dynamic framework. And the mixed framework was linked with two pure Objective-C dynamic frameworks.

When I tried to mark any class in the mixed framework with IB Designable and using that class in either storyboard or nib, the Xcode always says the instance of it was failed to render.

And there was the error message:

IB Designables: Failed to render instance of WZUITokenField: dlopen(WZUIKit.framework, 1): Library not loaded: /Library/Frameworks/WZFoundation.framework/WZFoundation Referenced from: WZUIKit.framework Reason: image not found

IB Designables: Failed to update auto layout status: dlopen(WZUIKit.framework, 1): Library not loaded: @rpath/WZFoundation.framework/WZFoundation Referenced from: WZUIKit.framework Reason: image not found

The framework WZUIKit is an Objective-C and Swift mixed framework and the WZFoundation is pure Objective-C.

Plus, all these sutff work on either device or the simulator.

WeZZard
  • 3,536
  • 1
  • 23
  • 26
  • In InterfaceBuild you don't have access to properties which are only available at application runtime, such as `AppDelegate`. This may cause this issues. – zisoft Nov 07 '14 at 10:35
  • 1
    I dont't think this issue was caused by accessing runtime properties but incorrect build setting. This issue is very similar to an issue i encountered before where the application was failed to load the custom framework when the target was only linked with the custom frameworks but not got them embedded. – WeZZard Nov 07 '14 at 10:55
  • another solution: http://stackoverflow.com/a/38368740/2245240 – Yaro Jul 14 '16 at 08:08

15 Answers15

84

Finally, I solved this issue by adding $(CONFIGURATION_BUILD_DIR) in the target's build settings' Runpath Search Paths field.

Plus, there are some additional steps you might need to do with your Xcode.

  1. Clear Xcode derived data for the project. They are in ~/Library/Developer/Xcode/DerivedData
  2. Clean your current build by pressing K
  3. Build your project
  4. In storyboard go to Editor menu and do Refresh All Views; wait for build to be completed and errors should be gone

Credit to @Mojtaba

Muhammad Nabeel Arif
  • 19,140
  • 8
  • 51
  • 70
WeZZard
  • 3,536
  • 1
  • 23
  • 26
  • 5
    The build setting is called "Runpath Search Paths" not "Run Search Path" – isaiah Feb 26 '15 at 19:24
  • 1
    I add that, and it doesn't help. What more should I do? – Bartłomiej Semańczyk Jun 25 '15 at 06:49
  • 4
    @WeZZard To improve your answer consider adding following steps after updating the field. 1. Clear Xcode derived data for the project. 2. Do clean/build 3. in storyboard go to edit and do "update all views" wait for build to be completed and errors should be gone – Mojtaba Jul 20 '15 at 19:09
  • 1
    Same, I had to add this to every project in my workspace – Adam Waite Oct 29 '15 at 11:03
  • 2
    I'm having the exact same issue, but this solution doesn't do it for me. Did anyone try this recently? Xcode 7.3 / Swift 2.2? I'm using CocoaPods for adding the dependencies to my app, by the way, version 1.0.0-rc.2. – Stefan May 09 '16 at 10:56
  • @Stefan did you find a solution? I have same problem with Xcode 7.3 and Swift 2.2 – nahive May 18 '16 at 10:16
  • Trier all that. No success. Also tried the Search Paths from the other answers. Trying to use it in a OS X app (no CocoaPods) :( Library not loaded: @executable_path/../Frameworks/libssh2.dylib Reason: image not found – Daniel Jun 23 '16 at 05:21
  • This caused my IB agent to crash. Didn't help. – nickdnk Apr 09 '18 at 17:06
  • This worked for me too... but why. How come I need to add some obscure build setting, is there any documentation related to this? – trapper Jan 07 '22 at 01:43
20

If you have the same issue building a Mac App, adding @loader_path/../Frameworks to Runpath Search Paths solved this for me.

Alex
  • 1,349
  • 11
  • 11
13

for me it works to close xcode and reopen it again. No errors after. Thanks.

Gabriel
  • 1,215
  • 13
  • 16
11

I hit this error on a framework containing IBDesignables.

I had to add $(FRAMEWORK_SEARCH_PATHS) to the LD_RUNPATH_SEARCH_PATHS setting on my framework target.

After updating the runpath setting, building, and refreshing the view in the storyboard, the error went away. Didn't even have to clean the build folder.

enter image description here

Scott Marchant
  • 3,447
  • 2
  • 22
  • 29
  • 1
    This worked for me! Thanks! Added `$(FRAMEWORK_SEARCH_PATHS)` and then clicked "Referesh All Views" in the "Editor" menu. – J.beenie May 10 '19 at 21:03
  • Important to say that this configuration works for framework development with dependencies. – OdNairy Feb 25 '21 at 15:26
  • This is the solution that fixed it for me, too. (Others offered here, such as `$(CONFIGURATION_BUILD_DIR)`, did not.) Thanks! – Ben Kennedy Apr 02 '21 at 22:47
5

Interesting.

First, WeZZard's answer got me going in the right direction but wasn't exactly my solution.

In my iOS project, something had overridden the Runpath Search Paths field in my target. It looked like this:

LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

I tried his solution of adding the $(CONFIGURATION_BUILD_DIR) but it didn't work for me. Since it wasn't working, out of habit I just deleted the configuration entry (going back to project defaults). When I did, it reset to this:

LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'

which if I dig into my xcconfig files, appears to come from the Cocoapods.

It seems same as Alex that the @loader_path is key, but it's a slightly different path on iOS than it is Mac OS X.

hsoi
  • 2,764
  • 3
  • 19
  • 20
  • 2
    I think you meant `'@executable_path/../Frameworks'` and `'@loader_path/../Frameworks'`. Depending on how the linked frameworks are built, one or the other paths may have been set on the binary, and for some reason this whole IBDesignable business chokes on this. In my case, I had to add the '@executable_path' in the above. – charles Mar 17 '16 at 16:35
  • Nope. I meant `@executable_path/Frameworks`. It depends upon Mac OS X (needs the `..`) or iOS (doesn't need). But you may be right that it may depend upon how the linked frameworks are built as well. What a joyous mess. While looking up some things just now, I saw some people solved it by adding all 4 (both variants). YMMV. – hsoi Mar 17 '16 at 16:39
  • Ah, right, iOS. Should have paid more attention, thanks! – charles Mar 17 '16 at 16:43
  • No worries. Good comment. – hsoi Mar 17 '16 at 16:45
  • Surprisingly this one helped me (with shorter exec paths) + close Xcode + nuke all derived data folder – Marek H Oct 25 '17 at 13:51
  • This one helped me. And I upgrade *Cocoapod* to `1.8.0` too. – AechoLiu Sep 25 '19 at 07:10
4

I had same problem In Xcode 6.4, adding Test target membership to the storyboard fixed these errors for me.

Also my test target has @loader_path/Frameworks set in Runpath Search Paths for test target, and not in original target.

enter image description here

CalZone
  • 1,701
  • 1
  • 17
  • 29
4

I also experienced this on a Mac project and Xcode 7.3.1. In my case, the framework referenced in the Failed to Render error message was not related to drawing at all.

Simply going to the target's General/Linked Frameworks and Libraries tab and changing the offending framework's Status from Required to Optional allowed the IBDesignables to update and draw properly in IB.

optional status

backslash-f
  • 7,923
  • 7
  • 52
  • 80
3

I just figured out another reason in my case:

When I used 'Editor -> Debug Selected Views' I saw that it crashed, because I was using CoreGraphics to create an image and use it as background image for a button:

class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {

    let rect = CGRectMake(0.0, 0.0, size.width, size.height);
    UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0);
    let context = UIGraphicsGetCurrentContext();    // It's alraedy nil here :(

    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);

    let image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;

}

The reason is simply that size is (0.0, 0.0). Why is that? I am calling

super.setBackgroundImage(UIImage.imageWithColor(bgColor, size: self.bounds.size), forState: .Normal)

But in IB self.bounds.size is still 0 at this point! So I changed one line:

let rect = CGRectMake(0.0, 0.0, max(size.width, 1.0), max(size.height, 1.0));

And now it works :)

Apple should provide a list with Dos and Don'ts regarding the IB...

benjamin.ludwig
  • 1,575
  • 18
  • 28
  • that's work for me! I finally use `Debug Selected Views` find out my problem. I draw things in `drawRect:`, and use properties which initiated in `initWithCoder:`, but when I debug, the code run into `initWithFrame:`, which the frame is {0, 0}, exactly @benjamin.ludwig's size problem. – walker Dec 24 '16 at 11:32
1

In my case, I was doing the next in the initWithFrame/initWithCoder methods to create the view:

className = NSStringFromClass([self class]);
self.view = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] firstObject];

But It looks like I was not supposed to use the Main Bundle but the bundle of the class. So I replaced that code for the following and it worked:

bundle = [NSBundle bundleForClass:[self class]];
className = NSStringFromClass([self class]);
self.view = [[bundle loadNibNamed:className owner:self options:nil] firstObject];

I thought maybe this might help somebody.

jmoukel
  • 794
  • 6
  • 18
1

I had this problem in an OS X project.

In my case, the problem was an old project (NMSSH) containing a framework target with bad build settings. Specifically:

  • INSTALL_PATH was set to @executable_path/../Frameworks, but the correct setting is /Library/Frameworks
  • SKIP_INSTALL was not set and defaults to NO, but the correct setting is YES
  • DYLIB_INSTALL_NAME_BASE was not set, but the correct setting is @rpath

Note that all of the correct settings are what you get automatically for a newly-created framework target.

After changing the settings to the correct values, Xcode was able to load my @IBDesignable view in the storyboard.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
1

In my case it inside private pod. Xcode Version 10.3 (10G8) produce rendering error

The solution is very simple in my case - I just forget to add public in-between of @IBInspectable var

right variant:

import UIKit

@IBDesignable public class BorderedView: UIView {
    @IBInspectable public var borderColor: UIColor? = UIColor.white {
        didSet {
            if let actualColor = borderColor {
                layer.borderColor = actualColor.cgColor
            } else {
                layer.borderColor = UIColor.white.cgColor
            }
            
            setNeedsDisplay()
        }
    }
    @IBInspectable public var borderWidth: CGFloat = 1 {
        didSet {
            layer.borderWidth = borderWidth
            setNeedsDisplay()
        }
    }
}

P.S.: Editor -> Debug Selected Views did nothing in my case

P.S.2 : AlignedCollectionViewFlowLayout pod from the dependency of my private pod and definitely not relevant to this issue.

P.S.3: Issue still here

Community
  • 1
  • 1
WINSergey
  • 1,977
  • 27
  • 39
0

I had a similar error which was caused by my Framework's views not having public initialisers:

public override init(frame: CGRect) {
    super.init(frame:frame)
    commonInit()
}

required public init(coder: NSCoder) {
    super.init(coder: coder)
    commonInit()
}
Leon
  • 3,614
  • 1
  • 33
  • 46
0

[I put this answer here for people like me finding this very similar thread without being able to find a solution]

I had a similar issue while using Cocoapods 1.9.1, the error message was related to a path error as follow (I added NewLines for the sake of lisibility):

error: IB Designables: 

Failed to render and update auto layout status for 

UITableViewController (kDz-VB-YcS): 

dlopen(YOUR_FRAMEWORK.framework, 1): 

Library not loaded: @rpath/YOUR_FRAMEWORK.framework/YOUR_FRAMWORKReferenced

from: YOUR_FRAMEWORK.frameworkReason: image not found

Here is the link to the thread: Cocoapods Issue 7606

And in the comments, someone posted a solution (that works for me). You need to put this post_install rule at the very end of your Podfile:

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    next unless config.name == 'Debug'
    config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = [
      '$(FRAMEWORK_SEARCH_PATHS)'
    ]
  end
end

Then execute again pod install, and it should now works

Hope it helps~

itMaxence
  • 1,230
  • 16
  • 28
-2

Follow the below steps:

  1. If there are any conflicts in the storyboard, resolve them correctly, check if the xml is correctly validated.(These is main step.)
  2. Clean the project.
  3. Delete the derived data folder.
  4. Quit Xcode and restart it again. (I had to do this twice.)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
komall
  • 1
  • 1
-3

Clear Derived Data . Quit Xcode, Reopen again.

Vineesh TP
  • 7,755
  • 12
  • 66
  • 130