Skip to content

Instantly share code, notes, and snippets.

@fitomad fitomad/typeof.swift
Created Feb 19, 2018

What would you like to do?
// An array with Int, Double and String types inside
let items: [Any] = [ 32, 32.0, "32" ]
for item in items
switch type(of: item)
case is Int.Type:
print("Type Int: \(item)")
case is Double.Type:
print("Type Double: \(item)")
case is String.Type:
print("Type String: \(item)")
print("No sé que es")
Type Int: 32
Type Double: 32.0
Type String: 32

This comment has been minimized.

Copy link
Owner Author

commented Feb 19, 2018

A different way to chech a var type in Swift.
Include another way to use de switch control flow statement (case is)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.