###前提・実現したいこと
テキストビューに入力した文字をcsvファイルに出力したい
###発生している問題・エラーメッセージ
コンパイルは通るが、シミュレータが動きません 2017-12-10 15:39:24.029120+0900 test [MC] Lazy loading NSBundle MobileCoreServices.framework 2017-12-10 15:39:24.030068+0900 test [MC] Loaded MobileCoreServices.framework 2017-12-10 15:39:24.044539+0900 test [MC] System group container for systemgroup.com.apple.configurationprofiles
と表示されているのですがどう変えていいか分かりません
###該当のソースコード
swift4
1import UIKit 2 3class ViewController: UIViewController { 4 5 @IBOutlet weak var textview: UITextView! 6 7 var data:[String] = [] 8 var userPath:String! 9 let fileManager = FileManager() 10 11 override func viewDidLoad() { 12 super.viewDidLoad() 13 do { 14 userPath = NSHomeDirectory()+"/Documents/sample.csv" 15 var path = userPath 16 if (fileManager.fileExists(atPath: path!) == false) { 17 path = Bundle.main.path(forResource: "sample", ofType: "csv")! 18 } 19 let csvData = try String(contentsOfFile:path!, encoding:String.Encoding.utf8) 20 data = csvData.components(separatedBy: "\n") 21 print(userPath) 22 } catch { 23 print(error) 24 } 25 } 26 27 28 func saveCSV() { 29 let outputstr = data.joined(separator: "\n") 30 let saveFile = FileManager.default.urls(for: .documentDirectory,in: .userDomainMask).last?.appendingPathComponent("sample.csv") 31 32 do { 33 if(outputstr == "") { 34 try fileManager.removeItem(atPath: userPath) 35 } else { 36 try outputstr.write( to: saveFile!, atomically: false, encoding: String.Encoding.utf8) 37 } 38 } catch { 39 print(error) 40 } 41 42 } 43 44 override func didReceiveMemoryWarning() { 45 super.didReceiveMemoryWarning() 46 47 } 48 49 50}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/09 03:47
2017/12/10 06:50