                     return completion("download for file '\(filepath)' failed with error: \(error)")
             }
             
-            let text = String(data: data, encoding: NSUTF8StringEncoding) ?? ""
+            let text = String(data: data, encoding: encoding) ?? ""
             let destinationText = try? String(contentsOfFile: filepath) ?? ""
             
             if !text.isEmpty && (text != destinationText) {
                 do {
-                    try text.writeToFile(filepath, atomically: true, encoding: NSUTF8StringEncoding)
+                    try text.writeToFile(filepath, atomically: true, encoding: encoding)
                     completion("successfully updated file '\(filepath)'")
                 } catch let error as NSError {
                     completion("writing to file '\(filepath)' failed with error: \(error)")

     
     - parameter files: the dictionary key is the path to the file in the app bundle relative to the project directory that should be updated if needed from the remote url string that is given as the corresponsing dictionary value. If the files' content have changed online and are not empty, the local files will be replaced by the downloaded remote files..
     - parameter header: optional dictionary with HTTP header fields
     - warning: Never call this method from app code as it calls `exit()`. It is designated to be called from a command line script.
     */
    public class func updateBundleFilesFromCLI(files: [String: String], header: [String: String]? = nil) {
        let group = dispatch_group_create()
        
        for (filepath, url) in files {
            dispatch_group_enter(group)
            updateBundleFile(filepath, url: url, header: header) { (message) in
                print(message)
                dispatch_group_leave(group)
            }

                    return
            }
            
            let text = replaceText(String(data: data, encoding: encoding) ?? "", replacingTexts: replacingTexts)
            if !text.isEmpty && (text != destinationText) {
                do {
                    try text.writeToFile(destinationPath, atomically: true, encoding: encoding)
                    didReplaceFile?(destinationURL: destinationURL, error: nil)
                } catch let error as NSError {
                    didReplaceFile?(destinationURL: destinationURL, error: error)
