以后绝对回用得着的东西:
swift2.1 类型转换String->Int, Float, Double
class CommonManager: NSObject {
static let sharedManager = CommonManager() //singleton
static func toStringValue(someValue: String?) -> String {
return someValue ?? ""
}
static func toIntValue(someValue: String?) -> Int {
return Int(CommonManager.toStringValue(someValue)) ?? 0
}
static func toDoubleValue(someValue: String?) -> Double {
return Double(CommonManager.toStringValue(someValue)) ?? 0.0
}
static func toFloatValue(someValue: String?) -> Float {
return Float(CommonManager.toStringValue(someValue)) ?? 0.0
}
}