Base64 Encoder/Decoder for Swift

Free online base64 encoder/decoder with Swift code examples

Working with base64 encoder/decoder in Swift? Our free online base64 encoder/decoder helps Swift developers format, validate, and process data instantly. Below you will find Swift code examples using Foundation (built-in) so you can achieve the same result programmatically in your own projects.

Try the Base64 Encoder/Decoder Online

Use our free Base64 Encoder/Decoder directly in your browser — no setup required.

Open Base64 Encoder/Decoder

Swift Code Example

import Foundation

// Encode
let data = "Hello, World!".data(using: .utf8)!
let encoded = data.base64EncodedString()
print(encoded)  // SGVsbG8sIFdvcmxkIQ==

// Decode
let decoded = Data(base64Encoded: encoded)!
print(String(data: decoded, encoding: .utf8)!)

Quick Setup

Library: Foundation (built-in)
// Built-in framework — no installation needed

Swift Tips & Best Practices

  • Data.base64EncodedString() is available on all Apple platforms
  • Use .lineLength76Characters option for MIME-style output
  • Always unwrap Data(base64Encoded:) safely — it returns nil on invalid input

Frequently Asked Questions

Base64 Encoder/Decoder in Other Languages

More Swift Tools