How to include my resource files in my framework without using a separate package?

I follow this tutorial to create an iOS static library: https://github.com/jverkoey/iOS-Framework#walkthrough . I managed to create a framework that can be imported into another Xcode project.

Now I want my framework to be able to show the storyboard. I believe the .storyboard file is considered a resource. The previous guide said that I should create a bundle for my resource files, such as images, instead of putting them in the structure itself.

However, I do want to put them in the environment itself. I do not want to use a separate package.

All the directories that I find tell me the same thing. I understand the benefits of using a separate package, but I just don't want to do it right now.

Now I get lost in how to include my .storyboard file in my structure so that I can show this with this:

 UIStoryboard *sb = [UIStoryboard storyboardWithName:@"NameOfStoryboard" bundle:[NSBundle bundleForClass:[self class]]]; UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"NameOfViewController"]; [otherView presentViewController:vc animated:YES completion:NULL]; 

The above code does not work (it cannot find the storyboard file). I assume this is due to the fact that .storyboard is not currently included in the structure. Unfortunately, I do not know how to enable it.

As part of the Xcode project, under the Build Phases section, I see the Copy Files tab, which looks the way I need it.

enter image description here

Now I'm not sure what this does, but it doesn't seem to work anyway.

I also did this:

enter image description here

How to include my .storyboard file in my infrastructure without using a separate package?

+7
ios objective-c xcode
source share
1 answer

Why do not you want to use a separate package for the framework? Therefore, if an application uses your framework, it will be able to use resources (Xibs, storyboards, whatever)

For example, a call from an application using your infrastructure might look something like this:

 FrameworkViewController *frameworkView = [[FrameworkViewController alloc] initWithNibName:@"FrameworkViewController" bundle:[NSBundle yourFrameworkBundle]]; 

and in your structure you can write a helper class NSBundle + YourFrameworkBundle that gives access to the structure package:

NSBundle + YourFrameworkBundle.h

 @interface NSBundle (YourFrameworkBundle) + (NSBundle *)yourFrameworkBundle; @end 

NSBundle + YourFrameworkBundle.m

 #import "NSBundle+YourFrameworkBundle.h" @implementation NSBundle (YourFrameworkBundle) + (NSBundle *)yourFrameworkBundle { static NSBundle *frameworkBundle = nil; static dispatch_once_t predicate; dispatch_once(&predicate, ^{ NSString *mainBundlePath = [[NSBundle mainBundle] resourcePath]; frameworkBundle = [NSBundle bundleWithPath:[mainBundlePath stringByAppendingPathComponent:@"YourFrameworkBundle.bundle"]]; }); return frameworkBundle; } @end 

To link resources for the framework, create a separate object in which you will link all your resources. enter image description here

-3
source share

All Articles