Skip to content

Instantly share code, notes, and snippets.

@nickarthur
Forked from mildocjr/typecast4.swift
Created February 5, 2019 21:21
Show Gist options
  • Select an option

  • Save nickarthur/4e22e8f8830e456e3f9f9f0c7b8ecc02 to your computer and use it in GitHub Desktop.

Select an option

Save nickarthur/4e22e8f8830e456e3f9f9f0c7b8ecc02 to your computer and use it in GitHub Desktop.
type-cast-4
var integerValue = 42
var stringValue = String(describing: 42)
var doubleValue = integerValue as! Double
var floatValue = Int(stringValue) as? Float
var array: [String] = ["eggs", "bacon", "ham", "cheese"]
let arrayCount = Double(array.count as? String)
var numArray: [Int] = [1, 2, 3, 4, 5]
var anotherDouble = numArray[3] as? Double
var isSunny = true
var sunnyString = String(describing: isSunny)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment