swift Localizable.string convert to csv

齐文林
2023-12-01

pod 'CSV.swift', '~> 2.4.3'

实现代码

import UIKit
import Foundation
import CSV
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        print(documentsPath)
        let filePath = documentsPath + "/" + "file.csv"
        let stream = OutputStream(toFileAtPath: filePath, append: false)!
        let csv = try! CSVWriter(stream: stream)
        if let url = Bundle.main.url(forResource: "Localizable", withExtension: "strings"),
            let stringsDict = NSDictionary(contentsOf: url) as? [String: String] {
            try! csv.write(row: ["English","Spanish"])
            for key in stringsDict.keys {
                try! csv.write(row: [key, stringsDict[key]!])
            }
        }
        csv.stream.close()
    }
}

 

 

 

 类似资料:

相关阅读

相关文章

相关问答