kstenerud / iOS-Universal-Framework

An XCode project template to build universal frameworks (arm7, arm7s, and simulator) for iOS / iPhone.
2.95k stars 473 forks source link

Using Resources - XIB #3

Closed randombits01 closed 13 years ago

randombits01 commented 13 years ago

You mentioned that you can add resources. I added a couple XIB files, built it, and added the framework to my project. If I expand the triangle next to my framework I can see my header files are listed but not the NIB files. When I look at the framework in Finder I can see the NIB files. I do an initWithNibName:@"MyFramework.framework/MyResource". This has a runtime error of: Could not load NIB in bundle. Can you get XIB resources to work? Or am I doing something wrong? Thanks!

kstenerud commented 13 years ago

Yeah, the resource copying doesn't work yet (I thought it was working, but it was just artifacts left over from an old build). I'll see if I can get this fixed sometime this week.

agius commented 13 years ago

Hi there - any luck with this? How would I investigate the cause of this? Is it a build setting, or does the script need to process resources into versioned directories like Apple's guide suggests?

kstenerud commented 13 years ago

I've managed to figure out how to make a true 100% real framework for iOS (rather than the "relocatable object file" hack I was using before). It solves a bunch of issues, and even copies resources into the framework, but unfortunately Xcode doesn't look inside static frameworks for resources (this is apparently an issue for Mac OS X static frameworks as well).

I'll have the new universal framework template uploaded later today (the new version requires modifications to xcode so I'm building an install script), but unless someone has figured out how to get Xcode to recognize static framework resources in OS X, there's not much hope in getting it to work for iOS =/

kstenerud commented 13 years ago

I've just checked in some changes that allow you to include resources in your framework!

Be sure to distribute the embeddedframework version rather than the framework version.

jspies commented 12 years ago

I've been trying to get this to work with my Core Data Models. The momd is in my embedded Framework's Resources folder, but it's not being recognized in mainBundle. I didn't see any other bundles with allBundles or allFrameworks. How should I be accessing the momd?

kstenerud commented 12 years ago

It looks like when building a core data model for a framework, Xcode doesn't quite do the same thing as it does when building an app.

A real app looks like this: ├── Info.plist ├── PkgInfo ├── TestMO ├── TestMO.momd │   ├── TestMO.mom │   └── VersionInfo.plist └── en.lproj ├── InfoPlist.strings └── MainWindow.nib

With an embeddedframwork, it looks like this:

├── Info.plist ├── PkgInfo ├── TestMO.mom ├── TestMOWithFW └── en.lproj ├── InfoPlist.strings └── MainWindow.nib

So instead of a .momd directory, it builds the .mom file and places it in the root. It still works in an app, but you need to load it as a .mom file, not a .momd file:

- (NSManagedObjectModel *)managedObjectModel {
    ...
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"TestMO" withExtension:@"momd"];

becomes:

- (NSManagedObjectModel *)managedObjectModel {
    ...
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"TestMO" withExtension:@"mom"];
jspies commented 12 years ago

That worked. It was a little misleading since the momd structure remains intact inside the Framework folder, but it seems when it is built within a project it goes straight to mom. Whatever happens, it worked changing to mom. Thanks for looking into it.

giant35 commented 12 years ago

hi, i use Mk5 real framework ,but xib not work. I add resource @class Controller1 & Controller1.xib in framework f1. Add f1.embeddedframework to app1 target's "link binary with libraries" . App crash at Controller1* c=[[Controller1 alloc] initWithNibName:@"Controller1" bundle:nil ]; raise exception on this line .

kstenerud commented 12 years ago

What exception is it raising?

giant35 commented 12 years ago

raise exception cause by not found Controller1.xib

kstenerud commented 12 years ago

I wasn't able to reproduce this issue. I did the following:

.

#import <MyXibFW/MyVC.h>

...

- (void) viewDidAppear:(BOOL)animated
{
    MyVC* vc = [[[MyVC alloc] initWithNibName:@"MyVC" bundle:nil] autorelease];
    [self presentModalViewController:vc animated:YES];
}

I've posted the projects here: http://www.mediafire.com/?r769bgkjr1jjfq0 MD5 (XibTest.zip) = b4824550feb1c2148c9b756c8bfcb7b8. Size = 184418