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
Correction
IBInspectable
andIB_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 theModule
in IB.Real life Example
Create a base class for iOS 7 (prior
IBInspectable
)Create a child class for iOS 8
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.