关于Swift 3[周五]
不知不觉周三了。这三天做注册登录模块 - -! 关于Swift 3然而是用swift做的! 虽然还是会用相当长一段时间来熟悉swift 3。 但是还是 觉得可以的,健壮性好! 这种好处,新手很难发现的。但是工程一大就知道有多好了。 Swift 3好处1 swift 3 应该是一个值得投资的语言。因为它是强类型的脚本,而且有过之而无不及,它把nil和有值(就是Optinal对象)也变成一种强类型,这样做在代码中留下了足够的提示。可读性非常好,后人维护非常简单。 黑科技清警告,曾经用此代码一次干掉了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
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |