//
// UserAccountViewModel.swift
// yadaService
//
// Created by YADA-SJ on 2018/5/18.
// Copyright © 2018年 . All rights reserved.
//
// 客户信息视图模型
import UIKit
import Alamofire
import SwiftyJSON
class CustomerViewModel {
//单例:避免重复比沙盒加载归档文件,提高效率,便于被访问到
static let sharedAccount=CustomerViewModel()
var customer:Customer?//客户账户模型
///登录标记
var userLogin:Bool{
return customer?.data?.username != nil
}
///返回归档保存的路径 计算型属性(类似于有返回值的函数)
var customerPath: String {
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory
, .userDomainMask, true).last!
return (path as NSString).appendingPathComponent("customer.plist")
}
/// 构造函数 -私有化 会要求外部只能通过单例常量访问,而不能()实例化
private init() {
print(customerPath) //打印路径
// 从沙盒解档数据,恢复当前数据
c
swift-viewModel以客户信息为例
最新推荐文章于 2024-05-21 16:20:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)