title: XCode accessing custom framework bundles resources i.e. images, xib files
body: <p>I am creating a custom framework which contains many classes which I will be using in several different projects. I will be giving this library out to other developers so I need my code protected</p>
  
  <p>I came across this tutorial which seems to be very useful</p>
  
  <p><a href="http://codefriend.blogspot.co.uk/2011/09/creating-ios-framework-with-xcode4.html" rel="nofollow noreferrer">http://codefriend.blogspot.co.uk/2011/09/creating-ios-framework-with-xcode4.html</a></p>
  
  <p>Using this, I have managed to turn my app into a framework, and all the classes are copied across and the code is protected as all the users will see is the .h files. So I can add this to any future apps, however I do not know how to access the resources, i.e images and XIB files.</p>
  
  <p>One work around for images is to turn the .png files into a .png.h file, process is this</p>
  
  <pre><code>1) Open a terminal and "cd" to the directory that holds myImage.png
  2) Run the command "xxd -i myImage.png myImage.png.h" -- This will turn the image into a .h header file
  3) Include the new myImage.png.h file in the framework before building and make it a public header
  4) After adding the framework to the project using it, import myImage.png.h
  5) Load the data into a NSData object with [NSData dataWithBytes:myImage_png length:myImage_png_len];
  </code></pre>
  
  <p>This works fine for images, even if it is kind of messy way of doing it. However this does not seem to work for XIB files. As a test, in my framework project, I created a new UIViewController called TestController, then, I create the framework, add that to my new project, then try and access it like this</p>
  
  <pre><code>NSData *data = [NSData dataWithBytes:TestControllerVC_xib length:TestControllerVC_xib_len];
      NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      TestControllerVC *test = [[TestControllerVC alloc]initWithNibName:str bundle:nil];
  
      [self.navigationController pushViewController:test animated:YES];
  </code></pre>
  
  <p>The app crashes with this error</p>
  
  <pre><code>&gt;     *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in
  &gt; bundle: 'NSBundle &lt;/Users/adam/Library/Application Support/iPhone
  &gt; Simulator/6.1/Applications/E9AEE10A-27A0-4363-B81D-D1DBE5DC7A51/TestAppWithFrameworkLib.app&gt;
  &gt; (loaded)' with name &lt;?xml version="1.0" encoding="UTF-8"?&gt;.... (rest of xml printed)'
  </code></pre>
  
  <p>(It prints the XML of the TestController class, didn't want to clog up post with the whole xml file)</p>
  
  <p>My question is, is there a better way of accessing the resources? If I access the TestBundle.Framework folder in my directory, you can see the resources file, but when you add the framework to your app, all you see is the header folder (see image below)</p>
  
  <p>Is there a reason the resources folder isn't shown when you add the framework to your app? Is there anyway I can access the resources, as the xib file is definitely added to the resources as you can see in the image below. Any help would be much appreciated!!!</p>
  
  <p><img src="https://i.stack.imgur.com/4BCRI.png" alt="Figure "></p>
  
  <p><img src="https://i.stack.imgur.com/I4RvW.png" alt="enter image description here"></p>