Swift获取某个bundle
func ext_SwiftBundle(podName:String) -> Bundle? {
let bundlePath:String? = ext_SwiftBundlePath(podName:podName)
return Bundle(path: bundlePath ?? "")
}
func ext_SwiftBundlePath(podName:String) -> String? {
var bundlePath: String?
for bundle: Bundle in Bundle.allBundles {
bundlePath = bundle.path(forResource: podName, ofType: "bundle")
if bundlePath != nil && bundlePath?.count != 0 {
return bundlePath
}
}
for bundle: Bundle in Bundle.allFrameworks {
bundlePath = bundle.path(forResource: podName, ofType: "bundle")!
if bundlePath != nil && bundlePath?.count != 0 {
return bundlePath
}
}
return bundlePath
}
Object-C获取某个bundle
+ (NSString*)jdd_bundlePathForPod:(NSString*)podName
{
for (NSBundle* bundle in [NSBundle allBundles]) {
NSString* bundlePath = [bundle pathForResource:podName ofType:@"bundle"];
if (bundlePath) {
return bundlePath;
}
}
for (NSBundle* bundle in [NSBundle allFrameworks]) {
NSString* bundlePath = [bundle pathForResource:podName ofType:@"bundle"];
if (bundlePath) {
return bundlePath;
}
}
return nil;
}
|