iOS 项目架构以及注意事项规范

今天写这篇文章是为了众多开发者少走翻路。文章主要是项目从初期到结束的架构以及注意事项规范。文笔不好请大家见谅。

一:mvc架构结构目录

     1.  viewModel:存放各种业务逻辑与网络请求

#pragma mark -  登录 app

-(void) landAPP:(NSString *)phoneNo passWord:(NSString *)password version:(NSString *)version model:(NSString *)model

{

    NSDictionary *parameter = @{PHONENO :phoneNo ,

                                PASSWORD:password,

                                VERSION:version,

                                MODEL:model

                                };

    [NetRequestClass NetRequestGETWithRequestURL:URL_LOGIN WithParameter:parameter WithReturnValeuBlock:^(id returnValue) {

        

       //处理请求数据

        

    } WithErrorCodeBlock:^(id errorCode) {

        DDLog(@"%@", errorCode);

        [self errorCodeWithDic:errorCode];

        

    } WithFailureBlock:^{

        [self netFailure];

        DDLog(@"网络异常");

        

    }];

    

}


2. viewController:存放ViewController类资源文件,也就是View层 

   

    LandViewModel *publicViewModel = [[LandViewModel allocinit];

    [publicViewModel setBlockWithReturnBlock:^(id returnValue) {

        //view层处理

        [SVProgressHUD dismiss];

        

    } WithErrorBlock:^(id errorCode) {

        [SVProgressHUD dismiss];

        

    } WithFailureBlock:^{

        

        [SVProgressHUD dismiss];

        

    }];

    

    NSDictionary *infoDictionary = [[NSBundle mainBundleinfoDictionary];

    NSString *version = [infoDictionary objectForKey:@"CFBundleVersion"];

    NSString *model=[[UIDevice currentDevicemodel];

    [publicViewModel landApp:phonNo passWord:pass version:version model:model];

    [SVProgressHUD showWithStatus:@"正在登录……" maskType:SVProgressHUDMaskTypeBlack];



3. model:存放你的get和set属性


@interface PublicModel : NSObject

@property (strongnonatomicNSString *age;

@property (strongnonatomicNSString *sex;


4. config:工程配置文件

 pch文件

 你可以建立自己的.h文件放置你的配置文件 如:

#ifndef Prj_Config_h

#define Prj_Config_h

 //请求公共微博的网络接口

#define REQUESTPUBLICURL @"https://api.weibo.com/2/statuses/public_timeline.json”


#define PHONENO @"phoneNo"

#define PASSWORD @"passWord"

#define VERSION @“version"


#endif


5. vendor:就不用说了,第三方库


6.Resource:就是工程的资源文件,下面有图片资源和Storyboard文件资源


二:项目中单例模式使用

       

许多开发者常常缺少对单例模式的使用,如请求为了避免实例多次被创建:

#import "ServiceManager.h"

@implementation ServiceManager

+(ServiceManager*)shareInstance{

    static ServiceManager *manager = nil;

    if (!manager) {

        manager = [[ServiceManager allocinit];

    }

    return manager;

}

- (id)init

{

    if(self = [super init])

    {

        [self initManagers];

    }

    

    return self;

}

-(void)initManagers{

 

    _fSearchService = [[FDSearchService allocinit];


}


#import "FDSearchService.h"


#pragma mark -搜索


-(void)registDownloadFoundationList:(NSDictionary *)dic dependCtr:(UIViewController*)ctr{

    NetworkRequestModel *model = [[NetworkRequestModel allocinitDependController:ctr];

    model.target = self;

    model.type = requestDownloadFoundationList;

    model.method = POST;

    model.parameters = dic;

    model.selector =    @selector(responseDownloadFoundationList:networkModel:);

    [[HttpRequestManager sharedManagerrequestDataWithModel:model];

}


@end



三:注意规范事项

  

    1. 许多开发者在xcode工程中new group,只是在视觉效果上分好了几个文件夹,方便分类管理,但在finder中并不会创建新的文件夹。

      正确方式:在finder找到把工程,新建文件夹,这样方便代码维护。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值