我现在正在使用Swift和MVVM架构从头开始一个新项目。 我想设置文件&用于最佳实践的文件夹结构我可以轻松,易懂地导航和使用。
大多数教程都建议:
├─ Models
├─ Views
├─ ViewModels
├─ Stores
├─ Helpers
但我发现它非常缺乏,因为我不知道管理ViewModels
文件夹的最佳做法是什么。
来自现实世界超级可维护项目的任何好建议?
非常感谢! :)
答案 0 :(得分:1)
根据uncle Bob's Clean Architecture pattern,您可以将代码划分为3个图层:
演示文稿:所有框架(Cocoa)依赖的代码。所以把你的观点,ViewModels,Vierwcontrollers等等。
数据:与存储库交互的所有代码(如网络呼叫,数据库调用,用户默认值等)
域名:所有型号
答案 1 :(得分:0)
视图文件将创建在视图模型中实现为转义/非转义闭包的数据绑定,以更新ui标签,以及在更新视图模型变量时进行的操作。
我不确定如何组织视图文件夹,因为Xcode基本上迫使您制作视图控制器文件。
├─ Model
|-|Employee
|-|Customer
|
├─ View
├─ ViewModel
|-|EmployeeViewModel
|-|CustomerViewModel
|
├─ Utilities
|-|NetworkManagerSingleton
答案 2 :(得分:-2)
YourProject
│
│ Info.plist
|
├─── Model
│ UserModel.swift
│ ProductModel.swift
│ CartModel.swift
│
├─── View
│ Main.storyboard
│ LaunchScreen.storyboard
│ ProductCell.xib
│
├─── Controller
│ HomeVC.swift
│ ProductsVC.swift
│ CartVC.swift
│
├─── Utilities
│ │
│ └─── Extensions
│ UIViewController+Additions.swift
│ String+Additions.swift
│ Dictionary+Additions.swift
│ UIView+Additions.swift
│
├──── Helpers
│ │ CommonMethods.swift
│ │
│ └─── Constants
│ AppMessages.swift
│ Keys.swift
│ EndPoints.swift
├──── Services
│ APIManager.swift
│ Services.swift
│