-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put resources into a bundle #64
Conversation
Added a Podfile for the demo project with a reference to the current directory. This will use the podspec in the current directory to build the CTAssetsPickerController bundle. Removed all CTAssetsPickerController/* files from the demo target. These files will be compiled into the pod library that will be linked to the demo by cocoapods. Updated project settings to the ones recommended by Xcode. Added the Pods directory to gitignore.
@cabeca Thanks for your contribution and this comprehensive guide! but I need time to review the changes before merging it. |
@cabeca Hi, I did some test on your code. I agreed that moving all resources into bundle is a right track. But I found that proposed code is mainly targeted for Cocoapods users. It would be broken if developer use the traditional submodules method. Please consider wrapping all picker's resources into a bundle so that it can be work for submodules users. |
Hello @chiunam , sorry about not saying something sooner, but I've been somewhat busy lately.
I have a preference ;-) but I would like to know your unbiased opinion on this. |
Hi @cabeca , I've been busy on my own job too. Seems I have to postpone the next major release. Re the suggested solutions, I didn't realise that it cannot put the Cocoapods is good but I still have hesitation to make it as the only option. Though I have no usage statistics of this control, it has already reached 500+ stars on github. Making such huge changes might impact those rely on traditional development methodology. I just want to make it clear on every little thing. |
Hello @chiunam Sorry if I didn't make myself clear, but you can put anything you want inside the resource bundle, it's just a directory with files inside. The problem is that the So, besides options 1. and 2. specified above, I guess there is another option: 3- Include in the project a shell script to generate the bundle. This shell script would have to be run by the authors of this library every time a new resource is added (image or localization). It would mainly create CTAssetsPickerController.bundle directory and copy all the existing _.png and *.lproj into this bundle directory, much like cocoa pods does. This bundle directory would _not* be added to .gitignore and would be the single resource copied to the final product by cocoapods. This has the downside of duplicating resources (both the "source files" and the inside-the-bundle-files) but has the benefit of working for both submodule users and cocoa pods users alike. I still prefer the option number 1. Cocoapods is all about automation. The submodules approach is all about manual work. I think that submodule users are used to following instructions to use libraries (copy this, configure that, run this script once, etc...). As long as the instructions are clear and in the right "via Git Submodules" section of the README, I don't think that it will be a problem. But of course that is your call. |
@cabeca Thanks for your explanation. I have a clearer picture now. Please go for option 1 then. BTW, wish you Merry Christmas and prosperous New Year! |
9af35d8
to
a9e752b
Compare
Conflicts: CTAssetsPickerDemo.xcodeproj/project.pbxproj
a9e752b
to
1e80822
Compare
Hello @chiunam So I went ahead with option 1 and this is the result.
|
@cabeca Sorry about not responding for a long time. I have been very busy in the past few weeks. I hope this PR can be done in early February. You have my word. :) |
#64 Conflicts: CTAssetsPickerController.podspec CTAssetsPickerDemo.xcodeproj/project.pbxproj
* master: #81 Fix: Reload collectionView after calling de/selectAsset methods.
Thank you :-) |
Motivation
This MR makes all resources (images and strings) available in a bundle (CTAssetsPickerController.bundle) as opposed to being copied individually into the main bundle. This aims to clean the integration of this pod within the projects by containing all resources inside a bundle instead of scattering them all over the root of the App.
There are three main tasks for achieving this:
Creating the bundle
This was the easy part. Using
resource_bundles
in pod spec, we can specify which files get inside each bundle. I just created one bundle namedCTAssetsPickerController
with all the images and localization directories inside. This bundle will be copied to the final product, instead of all the files mentioned inresources
Loading resources from the bundle
To load the resources from this bundle I had to change every resource loading method
NSLocalizedStringFromTable()
and-[UIImage imageNamed:]
to load from the CTAssetsPickerController.bundle instead of the default main bundle. I created two new methods,CTAssetsPickerControllerLocalizedString
and- [UIImage ctassetsPickerControllerImageNamed:]
that do this. These methods are defined in two categories ofUImage
andNSBundle
.Adapting the Demo project
The Demo project was changed to use the pod as a library (much like any project using this pod) instead of having the .m files and resources directly in the App target. For that I added a Podfile for the demo project with a reference to the current directory. This will use the podspec in the current directory to build the
CTAssetsPickerController.bundle
and pod library.I then removed all CTAssetsPickerController/* files from the demo target because these files will be compiled into the pod library that will be linked to the demo by cocoa pods. Also removed .xcassets and .strings from the demo target because they will be included in the bundle that will be copied to the final product.
I also updated the project settings to the ones recommended by Xcode and added the Pods directory to gitignore.
I know this is a big MR, if you have any doubts please ask me about it.
Thanks!