一、
//swift
中枚举可以定义函数和属性
private enum GFFNetworkError: @H_502_24@ Int {
case emptyDataError = - 1
case emptyTokenError = - 2
错误描述
private var errorDescription: String {
switch self {
case .emptyDataError: return " 空数据 "
case .emptyTokenError: "Token 为空 "
}
}
根据枚举类型,返回对应的错误 func errror() -> NSError {
return NSError (domain: GFFErrorDomainName ,code: rawValue ,userInfo: [ GFFErrorDomainName : errorDescription ])
}
private enum GFFNetworkError: @H_502_24@ Int {
case emptyDataError = - 1
case emptyTokenError = - 2
错误描述
private var errorDescription: String {
switch self {
case .emptyDataError: return " 空数据 "
case .emptyTokenError: "Token 为空 "
}
}
根据枚举类型,返回对应的错误 func errror() -> NSError {
return NSError (domain: GFFErrorDomainName ,code: rawValue ,userInfo: [ GFFErrorDomainName : errorDescription ])
}
}
二 、
enum
GFFClass:
String
{
case emptyName = "emptyName"
case fullName = "fullName"
static func getName(type: Bool )->( String ) {
return type == false ? GFFClass . emptyName . rawValue : fullName . rawValue
}
case emptyName = "emptyName"
case fullName = "fullName"
static func getName(type: Bool )->( String ) {
return type == false ? GFFClass . emptyName . rawValue : fullName . rawValue
}
}
GFFNetworkError.
emptyDataError.
errror()
let name: String = GFFClass.
getName(true)