【发布时间】:2013-04-09 11:31:52
【问题描述】:
我已将一个子项目作为静态库添加到我的主项目中。
现在,在主项目中,我尝试加载子项目包中的内容。像这样的:
NSString *defaultStorePath =
[[NSBundle bundleForClass:[self class]] pathForResource:@"database" ofType:@"sqlite"];
但这返回 nil...
我该如何解决?
【问题讨论】:
-
[NSBundle bundleWithIdentifier:...]与您的子捆绑包的 CFBundleIndentifier 怎么样? -
我没有特别创建这个捆绑包。在哪里可以找到捆绑包标识符?简单的事情在 Xcode 上很复杂。
-
是否将“database.sqlite”复制到应用程序包中?它究竟位于捆绑包内的什么位置?
-
database.sqlite 被复制到包中。它在 MyBundle/MyBundle/coredata/database.sqlite 里面
-
galloway.me.uk/tutorials/ios-library-with-resources 你可以尝试按名称初始化包吗? Xcode 不会自动为库创建资源包,请浏览您的主包内容(在设备上或
iPhone Simulator目录)以明确您在那里拥有哪些文件,注意iPhone Simulator可能包含您已经拥有的文件从项目中删除。
标签: iphone ios ipad cocoa-touch cocoa