Skip to content

Commit

Permalink
- Fixed the strange formatting issue.
Browse files Browse the repository at this point in the history
- Updated the example

Note: “\t”, “\n” and “\r” will replace by empty string.
  • Loading branch information
vigneshuvi committed Nov 7, 2017
1 parent ee4965f commit 2484c77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 46 deletions.
58 changes: 13 additions & 45 deletions Examples/SampleSwift/SampleSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]", 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("[email protected]", 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 {
Expand All @@ -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"


}
2 changes: 1 addition & 1 deletion SwiftCSVExport/Sources/CSVExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2484c77

Please sign in to comment.