Int() / String()
Text ↔ number conversion.
Syntax
Int("25") // String(42)Description
Int("25") returns an Optional; you unwrap it with ! for the definite value. String(number) converts a number to text.
Example
Loading editor…
Expected output
30 42!
When to use?
Accounting for text coming from users/files.
Common mistakes
- ⚠️ Int("abc") returns nil; make sure it is a number before unwrapping with !.