Cache resolved app bundle

This commit is contained in:
Isaac 2023-12-18 02:07:17 +04:00
parent 820b038bbc
commit 41f05c73d8

View File

@ -1,15 +1,21 @@
#import <AppBundle/AppBundle.h> #import <AppBundle/AppBundle.h>
NSBundle * _Nonnull getAppBundle() { NSBundle * _Nonnull getAppBundle() {
NSBundle *bundle = [NSBundle mainBundle]; static NSBundle *appBundle = nil;
if ([[bundle.bundleURL pathExtension] isEqualToString:@"appex"]) { static dispatch_once_t onceToken;
bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]]; dispatch_once(&onceToken, ^{
} else if ([[bundle.bundleURL pathExtension] isEqualToString:@"framework"]) { NSBundle *bundle = [NSBundle mainBundle];
bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]]; if ([[bundle.bundleURL pathExtension] isEqualToString:@"appex"]) {
} else if ([[bundle.bundleURL pathExtension] isEqualToString:@"Frameworks"]) { bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]];
bundle = [NSBundle bundleWithURL:[bundle.bundleURL URLByDeletingLastPathComponent]]; } else if ([[bundle.bundleURL pathExtension] isEqualToString:@"framework"]) {
} bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]];
return bundle; } else if ([[bundle.bundleURL pathExtension] isEqualToString:@"Frameworks"]) {
bundle = [NSBundle bundleWithURL:[bundle.bundleURL URLByDeletingLastPathComponent]];
}
appBundle = bundle;
});
return appBundle;
} }
@implementation UIImage (AppBundle) @implementation UIImage (AppBundle)