billgarrison / SORelativeDateTransformer

SORelativeDateTransformer is a value transformer that generates a human-readable phrase expressing the relative difference between a given date and the current date.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when used with CocoaPods

nickbit opened this issue · comments

Hello Bill,

I get a crash when adding the library with CocoaPods and have the use_frameworks! flag in the Podfile
The crash is in the following method:

+ (NSBundle *)bundle {
    static NSBundle *bundle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSURL *url = [[NSBundle mainBundle] URLForResource:@"SORelativeDateTransformer" withExtension:@"bundle"];
        bundle = [[NSBundle alloc] initWithURL:url];
    });
    return bundle;
}

url is nil and it crashes the bundle initialization.

Here is a fix that you can add to avoid it:

+ (NSBundle *)bundle {
    static NSBundle *bundle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSURL *url = [[NSBundle mainBundle] URLForResource:@"SORelativeDateTransformer" withExtension:@"bundle"];
        if (url != nil) {
            bundle = [[NSBundle alloc] initWithURL:url];
        } else {
            NSURL *frameworkURL = [[NSBundle bundleForClass:self] bundleURL];
            NSURL *bundleURL = [frameworkURL URLByAppendingPathComponent:@"SORelativeDateTransformer.bundle"];
            bundle = [NSBundle bundleWithURL:bundleURL];
        }
    });
    return bundle;
}