hi, How are you guys , Yesterday a friend asked me how to deal with the pictures in the project , It's on Assets.xcassets Do you , I said yes ,

He asked ~

“ You'll pack it Bundle Do you ?”

“ ah ? I can't .”

“ Can't learn , What are you waiting for ?”


“ Oh , Take time .”

So this article came into being during this lunch break .

Following text :

What is? Bundle file ?

Simple understanding , Is the resource package . We will take many pictures ,XIB, Text files organized together , Pack into one Bundle file . Convenient to reference resources within the package in other projects .


Bundle Characteristics of documents ?

Bundle It's static , in other words , The resource files we include in the package are not compiled as a resource package . Which means ,bundle Package cannot contain executable files . It's just a resource , Resolved to specific 2 Base data .
make Bundle

1. Create a new project macOS Of Bundle project




2. name



3. Delete folders and info.plist file




4. delete Build Settings Inside Packaging Of info.plist File address for




5. set up Base SDK by iOS




6. Add resource files to be packaged into folder





7. I added a picture





8. compile , Then find the button below to open the folder




9. find Bundle file , Right click to display package content , See if you want to add resource files to it




10. After checking , take Bundle copy to iOS In the project




11. Start using




This is a way , There are other ways .



NSString * bundlePath = [[ NSBundle mainBundle] pathForResource: @ "MyBundle"
ofType :@ "bundle"];

NSBundle *resourceBundle = [NSBundle bundleWithPath:bundlePath];

UIViewController *vc = [[UIViewController alloc] initWithNibName:@"vc_name"
bundle:resourceBundle];
perhaps


UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 50,
50)];

NSString *imgPath= [bundlePath stringByAppendingPathComponent:
@"img_collect_success.png"];

UIImage *image_1=[UIImage imageWithContentsOfFile:imgPath];

[imgView setImage:image_1];



Or precompile


#define MYBUNDLE_NAME @ "MyBundle.bundle"

#define MYBUNDLE_PATH [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent: MYBUNDLE_NAME]

#define MYBUNDLE [NSBundle bundleWithPath: MYBUNDLE_PATH]