How can I have the same result by using the Split( ) method instead of componentsSeparatedByString( ) method:
public func className(obj: Any) -> String { return toString(obj.dynamicType).componentsSeparatedByString(".").last! } Try this:
// Swift 1.2 public func className(obj: Any) -> String { return split(toString(obj.dynamicType)) { $0 == "." }.last! } // Swift 2.0 public func className(obj: Any) -> String { return String(obj.dynamicType) .characters.split { $0 == "." } .map { String($0) } .last! } print(className(42)) // Int print(className("Hello world")) // String print(className(1.0)) // Double print(className([1,2,3])) // Array<Int>