Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities

See the essence through the problem!!

Once CocoaPod libraries are created, there are often other things you can do with them, such as importing resource files and creating branches.

1. Reference images, xib, storyboard, plist, etc

Drag the resource to the Assert directory of the POD’s CTLFoundation. You can split the resource into files and configure it in your PodSpec as follows:

s.resources = ['CTLFoundation/Assets/*/*.png','CTLFoundation/Classes/**/*.xib']
Copy the code

or

s.resource_bundles = {
   'CTLFoundation' => ['CTLFoundation/Assets/*/*.png','CTLFoundation/Classes/**/*.xib']
}
Copy the code

When using the resources property, the build files are copied directly to the client target’s mainBundle. However, there is a problem with this. The resources of the client target and the resources of the various pods are in the same layer of the same bundle, which can easily cause naming conflicts. To address this issue, CocoaPods has added a new attribute resource_bundles in 0.23.0. There are solutions to the former, of course. Resource access, self is any class in pod:

+ (UIImage *)imageInBoundleWithName:(NSString *)name {
    NSBundle *boundle = [NSBundle bundleForClass:[self class]];
    UIImage *image = [UIImage imageNamed:name inBundle:boundle compatibleWithTraitCollection:nil];
    return image;
}
Copy the code

The latter:

+ (UIImage *)imageInBoundleWithName:(NSString *)name {
    NSBundle *boundle = [NSBundle bundleForClass:[self class]];
    NSBundle *currentBoundle = [NSBundle bundleWithPath:[boundle pathForResource:@"CTLFoundation" ofType:@"bundle"]];
    UIImage *image = [UIImage imageNamed:name inBundle:currentBoundle compatibleWithTraitCollection:nil];
    return image;
}
Copy the code

Load xib:

NSBundle *xibBundle = [NSBundle bundleForClass:[self class]];
CTLView *view = [xibBundle loadNibNamed:@"CTLView" owner:nil options:nil].lastObject;
Copy the code

The latter:

NSBundle *xibBundle = [NSBundle bundleForClass:[self class]];
NSBundle *currentBundle = [NSBundle bundleWithPath:[xibBundle pathForResource:@"CTLFoundation" ofType:@"bundle"]];
CTLView *view = [currentBundle loadNibNamed:@"CTLView" owner:nil options:nil].lastObject;
Copy the code

2. Create branch POD libraries

The process for creating a branch POD library is different from the above process as follows:

  1. Like the above POD library making, through
  2. $ pod lib create BranchRepoDemo
    Copy the code
  3. Create the POD project file and edit the podSpec file as required. The source in the podSpec file should be set as follows:
  4. . s.source = { :git => 'https://github.com/xxx/BranchRepoDemo.git', :branch => "dev" } ......Copy the code
  5. Also make sure you pass
  6. $ pod lib lint
  7. No need to tag the project.
  8. Associate the remote Origin/Master branch
  9. Create a branch dev in the remote project repository
  10. There are the following operations in the local project repository:

Git branch commands in the terminal

$git pull origin dev // The local branch is associated with the remote branch. $git push origin dev // the local branch is associated with the remote branchCopy the code

After successful push, it can be used. The usage method is as follows:

Pod 'pod library name' : git = > 'https://github.com/xxx/BranchRepoDemo.git' : branch = > 'devCopy the code