关于Swift 3[周五]

不知不觉周三了。这三天做注册登录模块 - -!

关于Swift 3

然而是用swift做的! 虽然还是会用相当长一段时间来熟悉swift 3。 但是还是 觉得可以的,健壮性好! 这种好处,新手很难发现的。但是工程一大就知道有多好了。
1 String的index 变得比以前麻烦了! 以前用Range去各种拆分字符串无压力。现在用index去拆字符串感觉心好累!但是,还是为了可读性强!!!
2 swift的代码没有头文件的束缚。写Extension的欲望比以前强了!
3 closure 本质上变化不大
4 dispatch 和 for 循环都去掉了 C 风格。
5 Enum被增强,可谓相当实用。你甚至可以把和tpye相关的逻辑写到Enum里面去。

Swift 3好处

1 swift 3 应该是一个值得投资的语言。因为它是强类型的脚本,而且有过之而无不及,它把nil和有值(就是Optinal对象)也变成一种强类型,这样做在代码中留下了足够的提示。可读性非常好,后人维护非常简单。
2 以后苹果的平台语言是swift,如果swift再往前发展一大步。无疑,早点掌握swift是有好处的。
3 按照刻意练习的观点。我必须选择不同的方式来开发iOS才能得到进步,所以做Native的项目 ,在不考虑React Native的情况下。 Swift 3 是我的最佳选择。

黑科技清警告,曾经用此代码一次干掉了200+警告

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"


import......各种头文件

#pragma clang pop

宏文件的替代方案

别宏文件了,全局变量,全局方法,Extension,还不够你替代宏文件么。

关于Session管理类的设计

以手机号为唯一标识,每个手机号对应一个seesion的dictionary,便于管理和切换。 */

//
//  MMBSessionManager.swift
//  meimabang
//

//

import UIKit
// MARK: -  以下为session管理的字段
let Key_Current_VerifiedCode = "Key_Current_VerifiedCode"
let Key_Current_Uid = "Key_Current_Uid"
let Key_Current_Token = "Key_Current_Token"



/*  MARK: 类说明。以手机号为唯一标识,每个手机号对应一个seesion的dictionary,便于管理和切换。 */
class MMBSessionManager: NSObject {

    let Key_Current_Mobile = "Key_Current_Mobile"
    static var instance :MMBSessionManager = MMBSessionManager()
    static var shared: MMBSessionManager {
        return instance
    }



    func setCurrentMobilePhone(mobile:String)
    {
        UserDefaults.standard.setValue(mobile, forKey: Key_Current_Mobile)
    }

    func getCurrentMobilePhone() -> String?
    {
        return UserDefaults.standard.object(forKey: Key_Current_Mobile) as! String?
    }

    func setSessionValue(_ value:Any,forKey:String)
    {
        let  userID = self.getCurrentMobilePhone()
        if userID != nil
        {
            let path =  getDocumentPathForFileName(userID! + "_sessionDict")
            var dict:NSMutableDictionary? = NSMutableDictionary.init(contentsOfFile: path!)
            if dict == nil
            {
                dict = NSMutableDictionary()
            }
            dict![forKey] = value

            asynBacgroundTask({
                dict!.write(toFile: path!, atomically: true)

            })
        }

    }

    func getSessionValue(_ forKey:String)-> Any?
    {
        let  userID = self.getCurrentMobilePhone()
        if userID != nil
        {
            let path =  getDocumentPathForFileName(userID! + "_sessionDict")
            let dict:NSMutableDictionary? = NSMutableDictionary.init(contentsOfFile: path!)
            return dict![forKey]
        }
        return nil
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值