Help us understand the problem. What is going on with this article?

Swift2.0でQRコードを出力する

More than 5 years have passed since last update.

iOS7からQRコードを出力出来るようになりました。
iOS9になった今、WebViewが使えないiOSなんて無いと思いますがSwift2.0でもこの機能が使えるので、ちょっとおさらいです。

        let ciFilter = CIFilter(name: "CIQRCodeGenerator")
        ciFilter?.setDefaults()
        let qrString = "http://google.com"
        let data = qrString.dataUsingEncoding(NSUTF8StringEncoding)
        ciFilter?.setValue(data, forKey: "inputMessage")
        ciFilter?.setValue("L", forKey: "inputCorrectionLevel")
        let ciContext = CIContext()
        let cgimg = ciContext.createCGImage((ciFilter?.outputImage)!, fromRect: (ciFilter?.outputImage?.extent)!)
        let image = UIImage(CGImage: cgimg, scale: UIScreen.mainScreen().scale, orientation: UIImageOrientation.Up)
        imageView.image = image

いじょ!

noppefoxwolf
きつねすき、にんげんこわい
https://noppelab.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away