Skip to content

Instantly share code, notes, and snippets.

@funkydevil
Last active November 20, 2018 09:22
Show Gist options
  • Save funkydevil/a0c2804be60cdd3021effe35340347c3 to your computer and use it in GitHub Desktop.
Save funkydevil/a0c2804be60cdd3021effe35340347c3 to your computer and use it in GitHub Desktop.
qr code from string
import Foundation
extension String {
func qrCode() -> UIImage? {
if self.isEmpty { return nil }
let data = self.data(using: String.Encoding.ascii)
if let filter = CIFilter(name: "CIQRCodeGenerator") {
filter.setValue(data, forKey: "inputMessage")
let transform = CGAffineTransform(scaleX: 3, y: 3)
if let output = filter.outputImage?.transformed(by: transform) {
return UIImage(ciImage: output)
}
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment