Last active
November 20, 2018 09:22
-
-
Save funkydevil/a0c2804be60cdd3021effe35340347c3 to your computer and use it in GitHub Desktop.
qr code from string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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