Get into the habit of writing together! This is the 16th day of my participation in the "Nuggets Daily New Plan·April Update Challenge", click to view the event details .
Loading of resource files
Image resources
In daily development, using image resource files, all methods will UIImage
be imageNamed
used
self.imageView.image = [UIImage imageNamed:@"share_wechat"];
复制代码
- But the picture used is in the component project, which cannot be accessed in this way
The image resource storage location in the component, in the 组件/Assets
directory
The file that configures the component Pod
and writes to the resourceBundle
In the test project Example
directory, executepod install
In the test project, Bundle
access the image resources in the component by specifying
NSString *bundlePath = [[NSBundle bundleForClass:[self class]].resourcePath stringByAppendingPathComponent:@"/LGModuleTest.bundle"];
NSBundle *resoure_bundle = [NSBundle bundleWithPath:bundlePath];
self.imageView.image = [UIImage imageNamed:@"share_wechat" inBundle:resoure_bundle compatibleWithTraitCollection:nil];
复制代码
json
document
Encapsulate HomeViewController in the component and read the json
file in the component
json
The configuration path of the file, in the 组件/Assets
directory
The file that configures the component Pod
and writes to the resourceBundle
In the test project Example
directory, executepod install
read mode, specifyLGHomeModule.bundle
NSString *bundlePath = [[NSBundle bundleForClass:[self class]].resourcePath stringByAppendingPathComponent:@"/LGHomeModule.bundle"];
NSString *path = [[NSBundle bundleWithPath:bundlePath] pathForResource:[NSString stringWithFormat:@"Home_TableView_Response_%@", channelId] ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:path];
复制代码
xib
document
There is also a resource file, which is very similar to the picture, which is the xib
file that is often used in our development.
Access xib
files within components
read mode, specifyBundle
for (NSString *className in HomeTableViewCellIdentifiers.allValues) {
NSString *bundlePath = [NSBundle bundleForClass:[self class]].resourcePath;
[self.tableView registerNib:[UINib nibWithNibName:className bundle:[NSBundle bundleWithPath:bundlePath]] forCellReuseIdentifier:className];
}
复制代码
Communication decoupling
Modules at the same level communicate with each other, resulting in complicated communication codes. You have me I have you. The modification of a single module is likely to involve errors in other modules, which is not conducive to the maintenance of the project
At this time, the communication between modules should be sinking, and a common lower-level component should be extracted, so that the modules are decoupled and the codes are independent of each other.
For the above communication decoupling requirements, mainstream solutions can be divided into three types:
URL
routingtarget-action
protocol
We describe these options in detail in subsequent articles.