calimarkus/JDFlipNumberView

NSBundle for `imageBundleName` should be configurable

johnboiles opened this issue · 2 comments

JDFlipNumberViewImageFactory.m lines 53 and 96 use [NSBundle mainBundle] as the bundle from which to load the digit images. This causes trouble when trying to use JDFlipNumberView as a framework, with Carthage, or in an IB_DESIGNABLE since the bundle for JDFlipNumberView is not necessarily the same as [NSBundle mainBundle].

Unfortunately, the fix isn't as simple as just replacing [NSBundle mainBundle] with [NSBundle bundleForClass:[self class]] since the default images JDFlipNumberView.bundle will be in the JDFlipNumberView bundle, but any custom images may be in another bundle.

Probably the right solution is to allow the option of passing an NSBundle object along with the image bundle name. For example, here are a few methods that would get renamed.

- (void)generateImagesFromBundleNamed:(NSString*)bundleName;

becomes

- (void)generateImagesFromImageBundleName:(NSString*)imageBundleName inBundle:(NSBundle*)bundle;

And

- (void)setImageBundleName:(NSString*)imageBundleName;

becomes

- (void)setImageBundleName:(NSString*)imageBundleName inBundle:(NSBundle*)bundle;

If necessary, the old methods could stick around for backwards compatibility. They would just call the new methods with [NSBundle mainBundle] for the bundle parameter

Sounds fair. Wanna put up a PR?

Actually it would be nicer to take the bundle name / bundle out of all the methods. We could have a different shared instance method, like sharedInstanceForBundleName:inBundle:.. We would need to keep around multiple instances then. But it would be cleaner.