0

My project is Obj-C only. Via Cocoapods, I tried installing an Obj-C library that takes advantage of IBDesignable and IBInspectable. If I add that project to my library and run 'pod install' I get two errors when building/running:

error: IB Designables: Failed to update auto layout status: Failed to load designables from path (null)
error: IB Designables: Failed to render instance of PKCircleProgressView: Failed to load designables from path (null)

Ok, so apparently to take advantage of IBDesignable/IBInspectable, your code needs to be in a framework, not a static library. It seems that all I need to do then is add this to my Podfile:

use_frameworks!

When I do that, I'm able to see everything in Interface Builder, but when I build/run, it can't find AFNetworking.h. I don't think the error is specific to AFNetworking, it's just the first pod in my Podfile.

If I was using Swift, it seems like the answer is that I need to add all the libraries from my Podfile into my Swift/Obj-C bridging header.

Even though I'm not using Swift, do I still need to create a bridging header?

Here's my Podfile (without the DownloadButton pod, and without use_frameworks!):

platform :ios, '8.0'
pod 'AFNetworking'
pod 'FMDB'
pod 'HKCircularProgressView'
#pod 'Taplytics'
pod 'PAPreferences'
pod 'HTMLLabel'
pod 'IDMPhotoBrowser'
pod 'MBProgressHUD'

link_with 'Langham', 'Leela', 'Las Alcobas', 'Siam', 'AKA BH', 'Ritz Montreal', 'Fullerton', 'Fullerton Bay'

# Fix broken copy-resources phase per https://github.com/CocoaPods/CocoaPods/issues/1546
post_install do |installer|
    installer.pods_project.targets.each do |target|
        scriptBaseName = "\"Pods/Target Support Files/#{target.name}/#{target.name}-resources\""
        sh = <<EOT
        if [ -f #{scriptBaseName}.sh ]; then
            if [ ! -f #{scriptBaseName}.sh.bak ]; then
                cp #{scriptBaseName}.sh #{scriptBaseName}.sh.bak;
            fi;
            sed '/WRAPPER_EXTENSION/,/fi\\n/d' #{scriptBaseName}.sh > #{scriptBaseName}.sh.temp;
            sed '/*.xcassets)/,/;;/d' #{scriptBaseName}.sh.temp > #{scriptBaseName}.sh;
            rm #{scriptBaseName}.sh.temp;
        fi;
EOT
        `#{sh}`
    end
end
djibouti33
  • 12,102
  • 9
  • 83
  • 116

1 Answers1

1

Correction

IBInspectable and IB_DESIGNABLE are not Swift related. They can be used in either Swift or Objective-C. It's a matter of iOS version, and occasionally of setting the Module in IB.

Real life Example

iOS 7 does not support IBInspectable, so use the .7 class for both controls. If your project targets iOS 8+, you should use TGPDiscreteSlider & TGPCamelLabels instead

Create a base class for iOS 7 (prior IBInspectable)

@interface TGPCamelLabels7 : UIControl...

@property (nonatomic, assign) CGFloat ticksDistance;
@property (nonatomic, assign) NSUInteger value;
// ...

Create a child class for iOS 8

@interface TGPCamelLabels : TGPCamelLabels7

@property (nonatomic) IBInspectable CGFloat ticksDistance;
@property (nonatomic) IBInspectable NSUInteger value;
// ...

In this manner, your Pod can be used in either mode. It has been solved, in details, on this TGPControls Pod.

Download the project, you will find 2 examples Xcode projects, one for Swift, 1 for Objective-C.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
  • Thanks. The problem I ended up having after including the DonwloadButton pod and adding `use_frameworks!` to my Podfile is that now my project failed to find the very first pod in my Podfile, AFNetworking. It's unclear to me how I'm supposed to use `use_frameworks!` with existing Pods that never needed that declaration. – djibouti33 Aug 09 '15 at 17:21
  • Please develop: `pod 'DownloadButton'` is not written in **Swift** and does not require `use_frameworks!` – SwiftArchitect Aug 09 '15 at 21:24
  • Is it either or?? If I'm using swift AND objective c using bridging headers, I cannot use IBDesignable? – mesh Mar 17 '16 at 14:24
  • 1
    It is not either *Obj-C* vs. *Swift*, it is **iOS 8+** vs. **iOS 7**. – SwiftArchitect Mar 18 '16 at 22:51