here\'s my code for generating QRCode image
+ (UIImage *)generateQRCodeWithString:(NSString *)string {
NSData *stringData = [string dataUsingEncoding:NSU
I had to adapt @cromanelli's answer to achieve perfect sharpness :
func convertTextToQRCode(text: String, withSize size: CGSize) -> UIImage {
let data = text.dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false)
let filter = CIFilter(name: "CIQRCodeGenerator")!
filter.setValue(data, forKey: "inputMessage")
filter.setValue("L", forKey: "inputCorrectionLevel")
var qrcodeCIImage = filter.outputImage!
let cgImage = CIContext(options:nil).createCGImage(qrcodeCIImage, fromRect: qrcodeCIImage.extent)
UIGraphicsBeginImageContext(CGSizeMake(size.width * UIScreen.mainScreen().scale, size.height * UIScreen.mainScreen().scale))
let context = UIGraphicsGetCurrentContext()
CGContextSetInterpolationQuality(context, .None)
CGContextDrawImage(context, CGContextGetClipBoundingBox(context), cgImage)
let preImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let qrCodeImage = UIImage(CGImage: preImage.CGImage!, scale: 1.0/UIScreen.mainScreen().scale, orientation: .DownMirrored)
return qrCodeImage
}