Loading a resource (e.g. storyboard) in a Swift framework
Here's a cleaner solution (no framework identifiers involved):
let storyboardName = "StoryboardName"
let storyboardBundle = NSBundle(forClass: self)
let storyboard = UIStoryboard(name: storyboardName, bundle: storyboardBundle)
If this code is not inside of a static
method, use YourClass.self
instead of self
.
Example for Swift 3:
let storyboardBundle = Bundle(for: NumberPadViewController.self)
super.init(nibName: "NumberPadViewController", bundle: storyboardBundle)
Go back to previous storyboard
I fixed it by getting the instance of a new view controller added on the user storyboard with the view controller identifier like so :
ProcessOut.backViewController = storyboard?.instantiateViewControllerWithIdentifier("back")
And then I present it like I would present a normal viewController from my storyboard.
How to load resource in cocoapods resource_bundle
I struggled with a similar issue for a while. The resource bundle for a pod is actually a separate bundle from where your code lives. Try the following:
Swift 5
let frameworkBundle = Bundle(for: XDWebViewController.self)
let bundleURL = frameworkBundle.resourceURL?.appendingPathComponent("XDCoreLib.bundle")
let resourceBundle = Bundle(url: bundleURL!)
let image = UIImage(named: "ic_arrow_back", in: resourceBundle, compatibleWith: nil)
print(image)
-- ORIGINAL ANSWER --
let frameworkBundle = NSBundle(forClass: XDWebViewController.self)
let bundleURL = frameworkBundle.resourceURL?.URLByAppendingPathComponent("XDCoreLib.bundle")
let resourceBundle = NSBundle(URL: bundleURL!)
let image = UIImage(named: "ic_arrow_back", inBundle: resourceBundle, compatibleWithTraitCollection: nil)
print(image)
Framework iOS-XIB can't load NIB in package
I found a solution to this problem,
push the xib file to the resource folder
spec.resources = "MobileAds/**/*.{png,jpeg,jpg,storyboard,xib,xcassets}"
Related Topics
How to Downscale a Uiimage in iOS by the Data Size
How to Compare Ssl Certificates Using Afnetworking
Removing from Array During Enumeration in Swift
Uiviewcontrollerhierarchyinconsistency When Trying to Present a Modal View Controller
Wkwebview Didn't Finish Loading, When Didfinishnavigation Is Called - Bug in Wkwebview
How to Deselect a Segment in Segmented Control Button Permanently Till Its Clicked Again
View at the Bottom in a Uiscrollview, with Autolayout
Uitextfield - Capture Return Button Event
How to Delete App Build in New Itunes Connect Site
How to Add Textfield in Uialertcontroller
Sendasynchronousrequest Was Deprecated in iOS 9, How to Alter Code to Fix
How to Subclass Uitableviewcontroller in Swift
How to Populate Uitableview from the Bottom Upwards
Avplayer Resuming After Incoming Call
Allow Uiscrollview and Its Subviews to Both Respond to a Touch
Uiwebview Random Crash at [Uiviewanimationstate Release]: Message Sent to Deallocated Instance