Overall IOS project level building and ios level building

Source: Internet
Author: User

Overall IOS project level building and ios level building

When creating an IOS project, if there is a clear hierarchical architecture, it will be helpful for future code maintenance or function expansion; this article will show some of my views on the hierarchy through an example. There are some fragmented knowledge points that may not be fully described, and the source code will be provided for download, I also hope that other better ideas can be put forward;

I. First, understand the entire project.

Note: Some third-party plug-ins are managed in conjunction with pods in the project. Several commonly used third-party plug-ins have been referenced in the project. These are common third-party plug-ins, I will not describe in detail here. You can learn about how to use pods through other online materials. You can also search for how to create multiple tags in a project on the Internet; you can also click here to view details;

Ii. Hierarchy of main items

Note: The Main project includes four modules: Main (Main), Expand (Extension), Resource (Resource), Vender (third-party), and the project has multiple tags, it is used to differentiate different versions, such as the test version of the local environment and the product version, mainly by Tag. Different identifiers correspond to different connection addresses. Of course, you can also set other different content;

2.1 Main (Main) Module Content

The main purpose of this module is to store the page content of the project, such as the content of MVC. The Base class is used to store some public content, and other functional modules are extracted to facilitate inheritance and calling; A public ViewController that has been sorted in BaseController in this instance


2.2 Expand (extended) Module Content

This module consists of six sub-modules: Const, Macros, Tool, NetWork, Category, and DataBase;

2.2.1 Macros (macro) mainly stores macro definitions. There are two macro files, Macros. h is the main macro of the project, such as the font, version, color value, and ThirdMacros. h is mainly used to store some key values of the third SDK;

2.2.2 Tool (Tool class) mainly stores some common classes. Here, Logger is used to store the encapsulation help class of logs, and Reachability is used to store the help class for judging the network status;

2.2.3 The YTKNetwork is the iOS Network library encapsulated by the IMG iOS R & D team based on AFNetworking. Some modifications are made to the YTKNetwork, to meet the requirements that different tags and functional modules may access different URLs;

2.2.4 Category (Category) mainly uses the iOS-Categories classification content in Git, and creates an Other to store the extended Categories;


2.3 Content of the Resource Module

The resource module consists of Global, Image, and Plist );

2.3.1 Global is used to store some Global content of the project, including the content of the startup Item LaunchScreen. storyboard, PrefixHeader. pch in the header, and File. strings in the Language Pack.

2.3.2 Image is used to store Image resources. Different xcassets files can be divided based on the function module;

2.3.3 Plist is used to store plist files. Multiple tags are created in this project, and each Tag has its own plist file for management. Therefore, it is easy to store and manage the Plist files in a unified manner;


2.4 content of the Vender (third-party) Module

Although the third-party plug-ins have been managed using pods in the project, some third-party plug-ins that may need to be modified can be stored here. Several commonly used third-party plug-ins referenced in this instance, A few of them are briefly introduced. gvuserults ults is an encapsulation of UserDefaults, which can be used for access operations simply. JDStatusBarNotification is a plug-in indicating the effect of the status bar. The plug-in such as time selection and options is displayed at the bottom of ActionSheetPicker; QBImagePickerController is a photo selection plug-in. You can select Multiple widgets and set the maximum number of photos;


Iii. Network Introduction

Because the project uses a lot of Network and this instance modifies it, I will explain it separately. First, I will share two connection addresses about YTKNetwork;

YTKNetwork basic tutorial

YTKNetwork advanced tutorial

For each request, this instance adds an access type to distinguish the corresponding connection prefix.

#ifndef NetWorkEnvironment_h#define NetWorkEnvironment_htypedef NS_ENUM(NSInteger,SERVERCENTER_TYPE){    ACCOUNT_SERVERCENTER,    PICTURE_SERVERCENTER,    BUSINESSLOGIC_SERVERCENTER,    UPDATEVERSION_SERVERCENTER};#endif /* NetWorkEnvironment_h */
# Import "NetWorkBaseUrlConfig. h "static NSString * const developer = @" developer "; static NSString * const product = @" product "; static NSString * const ACCOUNT_SERVERCENTER_Key = @" ACCOUNT_SERVERCENTER "; static NSString * const centers = @ "PICTURE_SERVERCENTER"; static NSString * const centers = @ "BUSINESSLOGIC_SERVERCENTER"; static NSString * const centers = @ "UPDATEVERSION_SERVERCENTER"; @ interface NetWorkBaseUrlConfig () @ property (nonatomic, assign) SERVERCENTER_TYPE netType; @ property (nonatomic, strong) NSMutableDictionary * configDictionary; // development and testing environment @ property (nonatomic, strong) NSDictionary * develpoerDictionary; // product environment @ property (nonatomic, strong) NSDictionary * productDictionary; @ end @ implementation NetWorkBaseUrlConfig + (instancetype) using config {static id share; static using onceToken; dispatch_once (& onceToken, ^ {share = [[NetWorkBaseUrlConfig alloc] init] ;}); return share ;}- (id) init {if (self = [super init]) {// test environment self. develpoerDictionary =@{ ACCOUNT_SERVERCENTER_Key: @ "http://private-eda65-mock.com/", PICTURE_SERVERCENTER_key: @ "image prefix", Subject: @ "business logic prefix", UPDATEVERSION_SERVERCENTER_key: @ "version upgrade prefix "}; // product environment self. productDictionary =@{ ACCOUNT_SERVERCENTER_Key: @ "http://private-eda66-mock.com/", PICTURE_SERVERCENTER_key: @ "image prefix", rule: @ "business logic prefix", UPDATEVERSION_SERVERCENTER_key: @ "version upgrade prefix "}; self. configDictionary = [NSMutableDictionary dictionary]; [self. configDictionary setObject: self. develpoerDictionary forKey: developer]; [self. configDictionary setObject: self. productDictionary forKey: product];} return self;}-(NSString *) urlWithCenterType :( SERVERCENTER_TYPE) type {NSString * urlResult = @ ""; NSString * validEnvironment = @""; // filter different tags # ifdef LOCAL validEnvironment = developer; # else validEnvironment = product; # endif NSString * urlKey = @ ""; switch (type) {case ACCOUNT_SERVERCENTER: urlKey = ACCOUNT_SERVERCENTER_Key; break; case PICTURE_SERVERCENTER: urlKey = break; case BUSINESSLOGIC_SERVERCENTER: urlKey = break; case UPDATEVERSION_SERVERCENTER: urlKey = break; default: break;} urlResult = self. configDictionary [validEnvironment] [urlKey]; return urlResult;} @ end

Note: # ifdef LOCAL identifies different tags. This project sets the Tag ID for LOCAL testing as LOCAL, and then sets the type of access for each request;

ACCOUNT_SERVERCENTER (logon address prefix), PICTURE_SERVERCENTER (image address prefix), BUSINESSLOGIC_SERVERCENTER (business logic prefix), UPDATEVERSION_SERVERCENTER (Version Upgrade prefix)

DevelpoerDictionary (test) and productDictionary (product) are used to store different connection prefix addresses. If tags of other versions are available, the corresponding dictionary is created;

#import "LogInApi.h"@interface LogInApi(){    NSString *_username;    NSString *_password;}@end@implementation LogInApi- (id)initWithUsername:(NSString *)username password:(NSString *)password {    self = [super init];    if (self) {        _username = username;        _password = password;    }    return self;}- (NSString *)requestUrl {    return @"user/login";}- (YTKRequestMethod)requestMethod {    return YTKRequestMethodPost;}-(SERVERCENTER_TYPE)centerType{    return ACCOUNT_SERVERCENTER;}- (id)requestArgument {    return @{             @"user_name": _username,             @"user_password": _password             };}@end

Set the access prefix to ACCOUNT_SERVERCENTER.

LogInApi * reg = [[LogInApi alloc] initWithUsername: @ "username" password: @ "password"]; [reg startWithCompletionBlockWithSuccess: ^ (YTKBaseRequest * request) {NSLog (@ "status code % ld", request. responseStatusCode); LoginModel * model = [[LoginModel alloc] initWithString: request. responseString error: nil]; NSLog (@ "response content: % @", model. access_token);} failure: ^ (YTKBaseRequest * request) {NSLog (@ "Error");}];

Call the operation content of the above Api, and perform JSONModel conversion on the Response content;


Other content navigation:

IOS more common third-party and instance (constantly updated) Address: http://www.cnblogs.com/wujy/p/4747998.html

IOS development basics fragment-Navigation Address: http://www.cnblogs.com/wujy/p/4571611.html


The source code of the project is still in progress. If you want to get the source code, you can leave an email address, which will be provided in a few days;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.