I'm getting an "unrecognized selector sent to instance" error when, in one Swift framework, I try to call a function that is defined as an extension to UIView within another Swift framework. It looks very similar to the problem that is solved by passing the -ObjC flag to the linker (https://developer.apple.com/library/ios/qa/qa1490/_index.html) and the problem that occurs when one extends a generic in a framework (Swift Framework does not include symbols from extensions to generic structs). Unfortunately, my problem appears to be different because:
- Both the framework that defines the extension and the framework that is trying to use it are written in Swift.
- Both frameworks are "Cocoa Touch Frameworks", not static libraries.
- The class being extended is UIView, not a generic.
- Adding -ObjC or -all_load to all of the targets involved didn't fix the problem.
The context is that I've added to an iOS project a framework target to house IBDesignable classes. The main project's name is "Vital," and the framework's name is "VitalDesignables." I've added another framework, named "VitalKit," to house code that both Vital and VitalDesignables depend on. VitalKit defines this function to load a view from a nib, a class in VitalDesignables tries to call it within init(frame: CGRect), and IB fails to load that class when I reference it in a storyboard.
public extension UIView {
public func loadViewFromNib(nibName: String) -> UIView {
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: nibName, bundle: bundle)
let topLevelItems = nib.instantiateWithOwner(self, options: nil)
let topLevelViews = topLevelItems.filter() { $0.isKindOfClass(UIView) }
precondition(topLevelViews.count == 1,
"There must be only one top-level view")
return topLevelViews.first as! UIView
}
}