iOS - Linking framework storyboard to ViewController for use in main project
To get it to find the view controller associated, all you need is -all_load -ObjC
in your apps Other Linker Flags in Build Settings.
it seems the linker leaves out the files necessary due to the apps code not actually using or referencing the ViewController, so the linker just leaves it out. This forces it to use the ViewController when linking now. (have a look at this answer for more detail)
i did this with just having my frameworks storyboard in a bundle along side my framework, i followed this guide for finding out how to make the bundle for the framework
Create iOS custom framework using storyboard and viewcontroller
You can reference a storyboard within your framework. You need to reference your framework's bundle specifically to get at the storyboard.
let bundle = Bundle(identifier: "com.custom.framework.bundle.id")
let storyboard = UIStoryboard(name: "NameOfStoryboard", bundle: bundle)
If the view/views are not complex in your storyboard, consider creating xib and a corresponding UIView file.
Is there any way to use storyboard and SwiftUI in same iOS Xcode project?
I just started to look at the SwiftUI
. Sharing a small example.
- In the
storyboard
addHosting View Controller
- Subclass the
UIHostingController
with your own class (ChildHostingController
) ChildHostingController
should look something like that:
import UIKit
import SwiftUI
struct SecondView: View {
var body: some View {
VStack {
Text("Second View").font(.system(size: 36))
Text("Loaded by SecondView").font(.system(size: 14))
}
}
}
class ChildHostingController: UIHostingController<SecondView> {
required init?(coder: NSCoder) {
super.init(coder: coder,rootView: SecondView());
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
For more details have a look at Custom UIHostingController
Apple Docs UIhostingController (Unfortunatelly it hasn't been documented yet)
Integrating SwiftUI Video
Xcode project use main interface from dynamic framework
I have found the problem to my issue, just answering here because it may be useful to someone else.
At the beginning my storyboard and my assets were all in my project, therefore I had no problem to load/link them. But when I moved them into a dynamic library (Cocoa framework touch) my app started crashing and it was because of the way that I was loading the assets that weren't any more in my project but in my framework.
So when I had everything in my project I was doing this:
[UIImage imageNamed:@"bar_grey_2.png"]
But after moving it to my framework I had to updated to:
[UIImage imageNamed:[[NSBundle bundleForClass:[self class]] pathForResource:@"bar_grey_1" ofType:@".png" inDirectory:nil]]
Jut a comment about dynamic frameworks, they are not supported in iOS7 and apple will refuse to accept any app aiming iOS7 with dynamic frameworks.
Accessing storyboard from custom framework not working
You need set Bundle
to access Storyboard.
First create storyboardBundle with Bundle Identifier for framework;
let storyboardName = "LoginScreen"
let storyboardBundle = Bundle(for: LoginUIModuleViewController.self)
or referencing a class in framework:
let storyboardBundle = Bundle(identifier: "com.yourframework.id")
Then create storyboard with this bundle:
let storyboard = UIStoryboard(name: storyboardName, bundle: storyboardBundle)
Loading a storyboard from a framework
Found the problem. Just silly but after deleting the Main.storyboard from the project, I didn't remove it from the project's settings. Trying to load it as the initial view controller. After changing the settings, UIStoryboard(name:"Main", bundle:NSBundle(forClass:self)
just works properly.
Related Topics
Creating an Image Format with an Unknown Type Is an Error Objective-C Xcode 8
How to Access an Iboutlet from Another Class
Errors Building Xcode Project After Adding in Run Script Fatal Error: Lipo: Input File
Instagram API Prevents Redirection to iOS App Upon Successful Login with 400 Bad Request Error
Nearby Bluetooth Devices Using Swift 3.0
Why Does Unexpected Non-Void Return Value in Void Function Happen
Facebook App Invites Notification Not Working in iOS
Get the Callers Phone Number from an Incoming Call on Iphone
How to Release an Mtaudioprocessingtap
Setting Up a Plist to Store Application Data (Not Settings) for an iPhone Game
Sending Latitude and Longitude to Server When App Is in Background
Swift Dynamic Table Cell Height
How to Create an Nsdecimal Without Using Nsnumber and Creating Autoreleased Objects
Firestore Paginating Data + Snapshot Listener
Application Identifier Entitlement Value Has Changed
Why Must a Protocol Operator Be Implemented as a Global Function