Skip to content

Commit 2484c77

Browse files
committed
- Fixed the strange formatting issue.
- Updated the example Note: “\t”, “\n” and “\r” will replace by empty string.
1 parent ee4965f commit 2484c77

File tree

2 files changed

+14
-46
lines changed

2 files changed

+14
-46
lines changed

Examples/SampleSwift/SampleSwift/ViewController.swift

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,32 @@ import SwiftCSVExport
1818

1919
class ViewController: UIViewController {
2020

21-
var task: String = ""
22-
23-
var tasks: String = ""
24-
25-
26-
var DMID: String = "123456789"
27-
var RECORDID: String = "PCA12345D"
28-
var First : String = "Leah"
29-
var Last : String = "Schmidt"
30-
var Company: String = "Lab Cab Inc"
31-
var Address1 : String = " 5442 Appaloosa Way"
32-
var Address2 : String = "First Floor"
33-
var City : String = "Loma Linda"
34-
var State : String = "Missouri"
35-
var Postalcode : String = "64804"
36-
var Country: String = "USA"
37-
var Sender:String = "Annie"
38-
var Frontimage : String = "Picture of Roo"
39-
var Backtext : String = "\nHi Leah\n Here is a photo of ROO\n Love\n Leah\n"
40-
var Accentimage : String = " NO Accentimage"
41-
var Backimage : String = "NO Backimage"
21+
4222

4323
@IBOutlet var webview: UIWebView!
4424
override func viewDidLoad() {
4525
super.viewDidLoad()
4626

4727

48-
// First User Object
28+
// Generate CSV file
4929
let user1:NSMutableDictionary = NSMutableDictionary()
30+
user1.setObject("vignesh", forKey: "name" as NSCopying);
31+
user1.setObject("[email protected]", forKey: "email" as NSCopying);
5032

51-
user1.setObject(DMID, forKey: "DMID" as NSCopying); //required
52-
user1.setObject(RECORDID, forKey: "RecordID" as NSCopying); //required
53-
user1.setObject(First, forKey: "First" as NSCopying); //required
54-
user1.setObject(Last, forKey: "Last" as NSCopying); //required
55-
user1.setObject(Company, forKey: "Company" as NSCopying); //required
56-
user1.setObject(Address1, forKey: "Address1" as NSCopying); //required
57-
user1.setObject(Address2, forKey: "Address2" as NSCopying); //optional
58-
user1.setObject(City, forKey: "City" as NSCopying); //required
59-
user1.setObject(State, forKey: "State" as NSCopying); //required
60-
user1.setObject(Postalcode, forKey: "Postalcode" as NSCopying); //required
61-
user1.setObject(Country, forKey: "Country" as NSCopying); //optional
62-
user1.setObject(Sender, forKey: "Sender" as NSCopying); //optional
63-
user1.setObject(Frontimage, forKey: "Frontimage" as NSCopying); //required
64-
user1.setObject(Backtext, forKey: "Backtext" as NSCopying); //optional
65-
user1.setObject(Accentimage, forKey: "Accentimage" as NSCopying); //optional
66-
user1.setObject(Backimage, forKey: "Backimage" as NSCopying); //optional
33+
let user2:NSMutableDictionary = NSMutableDictionary()
34+
user2.setObject("vinoth", forKey: "name" as NSCopying);
35+
user2.setObject("[email protected]", forKey: "email" as NSCopying);
6736

68-
69-
// CSV rows Array
7037
let data:NSMutableArray = NSMutableArray()
7138
data.add(user1);
72-
73-
74-
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);
39+
data.add(user2);
7540

41+
let filePath:String = SwiftCSVExport.exportCSV("userlist",fields: ["name", "email"],values: data);
7642
print(filePath)
43+
44+
let request = NSURLRequest(url: URL(fileURLWithPath: filePath) )
45+
webview.loadRequest(request as URLRequest)
46+
7747
//
7848
let fileDetails = readCSV(filePath);
7949
if fileDetails.allKeys.count > 0 {
@@ -87,7 +57,5 @@ class ViewController: UIViewController {
8757
super.didReceiveMemoryWarning()
8858
// Dispose of any resources that can be recreated.
8959
}
90-
var csvText = "DMID, RecordID, First, Last, Street,Apt., City, State, Postalcode\n"
91-
9260

9361
}

SwiftCSVExport/Sources/CSVExport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ extension String {
123123
open func write(text: String) {
124124
let path = "\(directory)/\(self.csvFileName())"
125125
let fileManager = FileManager.default
126-
let updatedString = text.replacingOccurrences(of: "\n", with: "0x0a").replacingOccurrences(of: "\t", with: "0x09").replacingOccurrences(of: "\r", with: "0x0d")
126+
let updatedString = text.replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\t", with: "").replacingOccurrences(of: "\r", with: "")
127127

128128

129129
if !fileManager.fileExists(atPath: path) {

0 commit comments

Comments
 (0)