Last active
May 27, 2017 19:53
-
-
Save OctoberHammer/671a2c4705272299560e61f37c90ebde to your computer and use it in GitHub Desktop.
Convert from Any? into Int32?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
import Foundation | |
//Пробовать с разными - раскоментаривать по очереди | |
var someString: String? = "bjbb" | |
//var someString: String? = "3456" | |
//var someString: Int? = 3456 | |
//var someString: Int? | |
func CastToInt32(someId: Any?) -> Int32? { | |
var identifier: Int32? | |
if let stateCode = someId as? Int ?? Int(someId as? String ?? "") { | |
identifier = Int32(stateCode) | |
return identifier | |
} else { | |
return nil | |
} | |
} | |
let myInt32 = CastToInt32(someId: someString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment