Skip to content

Instantly share code, notes, and snippets.

@frozzare
frozzare / template.swift
Last active July 24, 2018 15:54
Example of string replacement in Swift with a dictionary
import Foundation
class Template {
class func render (var str: String, dict: Dictionary<String, String>) -> String {
for (key, value) in dict {
str = str.stringByReplacingOccurrencesOfString("{\(key)}", withString: value)
}
return str
}