From 2484c77118b05ce05812e7a7f9e2677f261290d4 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Tue, 7 Nov 2017 14:09:49 +0530 Subject: [PATCH] - Fixed the strange formatting issue. - Updated the example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: “\t”, “\n” and “\r” will replace by empty string. --- .../SampleSwift/ViewController.swift | 58 +++++-------------- SwiftCSVExport/Sources/CSVExport.swift | 2 +- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/Examples/SampleSwift/SampleSwift/ViewController.swift b/Examples/SampleSwift/SampleSwift/ViewController.swift index 630e9dc..320a290 100644 --- a/Examples/SampleSwift/SampleSwift/ViewController.swift +++ b/Examples/SampleSwift/SampleSwift/ViewController.swift @@ -18,62 +18,32 @@ import SwiftCSVExport class ViewController: UIViewController { - var task: String = "" - - var tasks: String = "" - - - var DMID: String = "123456789" - var RECORDID: String = "PCA12345D" - var First : String = "Leah" - var Last : String = "Schmidt" - var Company: String = "Lab Cab Inc" - var Address1 : String = " 5442 Appaloosa Way" - var Address2 : String = "First Floor" - var City : String = "Loma Linda" - var State : String = "Missouri" - var Postalcode : String = "64804" - var Country: String = "USA" - var Sender:String = "Annie" - var Frontimage : String = "Picture of Roo" - var Backtext : String = "\nHi Leah\n Here is a photo of ROO\n Love\n Leah\n" - var Accentimage : String = " NO Accentimage" - var Backimage : String = "NO Backimage" + @IBOutlet var webview: UIWebView! override func viewDidLoad() { super.viewDidLoad() - // First User Object + // Generate CSV file let user1:NSMutableDictionary = NSMutableDictionary() + user1.setObject("vignesh", forKey: "name" as NSCopying); + user1.setObject("vigneshuvi@gmail.com", forKey: "email" as NSCopying); - user1.setObject(DMID, forKey: "DMID" as NSCopying); //required - user1.setObject(RECORDID, forKey: "RecordID" as NSCopying); //required - user1.setObject(First, forKey: "First" as NSCopying); //required - user1.setObject(Last, forKey: "Last" as NSCopying); //required - user1.setObject(Company, forKey: "Company" as NSCopying); //required - user1.setObject(Address1, forKey: "Address1" as NSCopying); //required - user1.setObject(Address2, forKey: "Address2" as NSCopying); //optional - user1.setObject(City, forKey: "City" as NSCopying); //required - user1.setObject(State, forKey: "State" as NSCopying); //required - user1.setObject(Postalcode, forKey: "Postalcode" as NSCopying); //required - user1.setObject(Country, forKey: "Country" as NSCopying); //optional - user1.setObject(Sender, forKey: "Sender" as NSCopying); //optional - user1.setObject(Frontimage, forKey: "Frontimage" as NSCopying); //required - user1.setObject(Backtext, forKey: "Backtext" as NSCopying); //optional - user1.setObject(Accentimage, forKey: "Accentimage" as NSCopying); //optional - user1.setObject(Backimage, forKey: "Backimage" as NSCopying); //optional + let user2:NSMutableDictionary = NSMutableDictionary() + user2.setObject("vinoth", forKey: "name" as NSCopying); + user2.setObject("vinoth@gmail.com", forKey: "email" as NSCopying); - - // CSV rows Array let data:NSMutableArray = NSMutableArray() data.add(user1); - - - let filePath:String = SwiftCSVExport.exportCSV("userlist1",fields: ["DMID", "RecordID", "First", "Last", "Company","Address1", "Address2", "City", "State", "Postalcode", "Country", "Sender","Frontimage", "Backtext", "Accentimage", "Backimage"],values: data); + data.add(user2); + let filePath:String = SwiftCSVExport.exportCSV("userlist",fields: ["name", "email"],values: data); print(filePath) + + let request = NSURLRequest(url: URL(fileURLWithPath: filePath) ) + webview.loadRequest(request as URLRequest) + // let fileDetails = readCSV(filePath); if fileDetails.allKeys.count > 0 { @@ -87,7 +57,5 @@ class ViewController: UIViewController { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } - var csvText = "DMID, RecordID, First, Last, Street,Apt., City, State, Postalcode\n" - } diff --git a/SwiftCSVExport/Sources/CSVExport.swift b/SwiftCSVExport/Sources/CSVExport.swift index cbff45f..60d2e4f 100644 --- a/SwiftCSVExport/Sources/CSVExport.swift +++ b/SwiftCSVExport/Sources/CSVExport.swift @@ -123,7 +123,7 @@ extension String { open func write(text: String) { let path = "\(directory)/\(self.csvFileName())" let fileManager = FileManager.default - let updatedString = text.replacingOccurrences(of: "\n", with: "0x0a").replacingOccurrences(of: "\t", with: "0x09").replacingOccurrences(of: "\r", with: "0x0d") + let updatedString = text.replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\t", with: "").replacingOccurrences(of: "\r", with: "") if !fileManager.fileExists(atPath: path) {