             let readableObject = lastMetadataObject as? AVMetadataMachineReadableCodeObject
         {
             if (readableObject.type == AVMetadataObjectTypeQRCode) {
-                // Construct a forum object with the scanned result.
-                if let jsonData = readableObject.stringValue.dataUsingEncoding(NSUTF8StringEncoding),
-                    let jsonDict = (try? NSJSONSerialization.JSONObjectWithData(jsonData,
-                                                                               options: .AllowFragments)) as? [String: AnyObject]
-                {
-                    capturedForum = KomicaForum(jsonDict: jsonDict)
-                    if ((capturedForum?.isReady()) != nil) {
-                        performSegueWithIdentifier(SegueIdentifier.addForum, sender: nil)
-                        return
-                    }
+                if parseJsonString(readableObject.stringValue) {
+                    return
                 }
             }
         }


// MARK: UI actions.

extension ForumQRScannerViewController {
    
    @IBAction func loadFromLibraryAction(sender: AnyObject) {
        
    }
    
    @IBAction func scanQRHelpBarButtonItemAction(sender: AnyObject) {
        
    }
}


        }
    }
    
    func parseJsonString(jsonString: String) -> Bool {
        // Construct a forum object with the scanned result.
        if let jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding),
            let jsonDict = (try? NSJSONSerialization.JSONObjectWithData(jsonData,
                options: .AllowFragments)) as? [String: AnyObject]
            where !jsonString.isEmpty
        {
            capturedForum = KomicaForum(jsonDict: jsonDict)
            if ((capturedForum?.isReady()) != nil) {
                performSegueWithIdentifier(SegueIdentifier.addForum, sender: nil)
                return true
            }
        }
        return false
    }
    
}

// MARK: Read from library
extension ForumQRScannerViewController {
    // Shamelessly copied from http://stackoverflow.com/questions/35956538/how-to-read-qr-code-from-static-image and modified to my need.
    func performQRCodeDetection(image: CIImage) -> [String] {
        let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorAspectRatio: 1.0])
        let features = detector.featuresInImage(image)
        var strings = [String]()
        features.forEach { feature in
            if let feature = feature as? CIQRCodeFeature {
                strings.append(feature.messageString)
            }
        }
        return strings
    }
    
}
