我在Xcode中創建了一個靜態庫,我可以在其他項目中成功使用它。然而,像plists這樣的資源,我發現我必須在我的圖書館中使用項目的主項目中引用任何plists。Obj-c靜態庫中的NSBundle,plist和其他資源
在我的靜態庫項目中,我將我的plist包含在目標的「Copy Bundle Resources」階段中。在我的代碼,這裏是我在做什麼:
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *filePath = [mainBundle pathForResource:@"MyClassParams" ofType:@"plist"];
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
如果我使用mainBundle和MyClassParams.plist包含在主體工程,一切都很好。如果MyClassParams.plist包含在庫項目中,則不起作用。
NSBundle *mainBundle = [NSBundle bundleForClass:[MyClass class]];
這也不能工作:
在假設[一個NSBundle mainBundle]被引用了錯誤的靜態方法來使用,我取而代之。
那麼,是否有可能在靜態庫中包含plist或任何其他資源 - 或者我必須在使用lib的項目中包含任何我需要的內容?
從這個問題開始賞金 - 是接受的答案仍然正確的iOS 4.2? – 2010-12-26 17:08:31