Skip to content

Commit 7fb3344

Browse files
committed
Updated sample code.
1 parent 76921bc commit 7fb3344

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

Examples/SampleSwift/Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ target 'SampleSwift' do
66
use_frameworks!
77

88
pod 'SwiftLoggly’
9-
pod 'SwiftCSVExport'
9+
# pod 'SwiftCSVExport'
1010
11-
# pod 'SwiftCSVExport', :git => 'https://github.com/vigneshuvi/SwiftCSVExport.git', :tag => '1.0.6'
11+
pod 'SwiftCSVExport', :git => 'https://github.com/vigneshuvi/SwiftCSVExport.git', :tag => '2.0.0'
1212
1313
# Pods for SampleSwift
1414

Examples/SampleSwift/SampleSwift/ViewController.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ViewController: UIViewController {
4141
user2.setObject("vinoth", forKey: "name" as NSCopying);
4242
user2.setObject(false, forKey:"isValidUser" as NSCopying)
4343
user2.setObject("[email protected]", forKey: "email" as NSCopying);
44-
user2.setObject("Hi 'Vinoth!', \nHow are you? \t Shall we meet tomorrow? \r Thanks ", forKey: "message" as NSCopying);
44+
user2.setObject("Hi 'Vinoth!'; \nHow are you? \t Shall we meet tomorrow? \r Thanks ", forKey: "message" as NSCopying);
4545
user2.setObject(567.50, forKey: "balance" as NSCopying);
4646

4747
let data:NSMutableArray = NSMutableArray()
@@ -53,7 +53,7 @@ class ViewController: UIViewController {
5353
user3.name = "John"
5454
user3.email = "[email protected]"
5555
user3.isValidUser = true
56-
user3.message = "Hi 'John!' \nHow are you? \t Shall we meet tomorrow? \r Thanks "
56+
user3.message = "Hi 'John!'; \nHow are you? \t Shall we meet tomorrow? \r Thanks "
5757
user3.balance = 105.41;
5858
data.add(listPropertiesWithValues(user3)) // Able to convert Class object into NSMutableDictionary
5959

@@ -66,29 +66,36 @@ class ViewController: UIViewController {
6666
writeCSVObj.name = "userlist"
6767

6868
// Write File using CSV class object
69-
let filePath:String = SwiftCSVExport.exportCSV(writeCSVObj);
70-
print(filePath)
71-
72-
73-
let request = NSURLRequest(url: URL(fileURLWithPath: filePath) )
74-
webview.loadRequest(request as URLRequest)
75-
76-
//
69+
let result = exportCSV(writeCSVObj);
70+
if result.isSuccess {
71+
guard let filePath = result.value else {
72+
print("Export Error: \(String(describing: result.value))")
73+
return
74+
}
75+
76+
print("File Path: \(filePath)")
77+
self.readCSVPath(filePath)
78+
} else {
79+
print("Export Error: \(String(describing: result.value))")
80+
}
81+
}
82+
83+
func readCSVPath(_ filePath: String) {
7784
let fileDetails = readCSV(filePath);
7885
if fileDetails.hasData {
7986
loggly(LogType.Info, dictionary: fileDetails)
8087
loggly(LogType.Info, text: fileDetails.name)
8188
loggly(LogType.Info, text: fileDetails.delimiter)
8289
}
8390

84-
// Read File in Object Oriented Way
85-
let readCSVObj = readCSVObject(filePath);
86-
91+
let request = NSURLRequest(url: URL(fileURLWithPath: filePath) )
92+
webview.loadRequest(request as URLRequest)
8793

94+
// Read File and convert as CSV class object
95+
let readCSVObj = readCSVObject(filePath);
8896

8997
// Use 'SwiftLoggly' pod framework to print the Dictionary
9098
loggly(LogType.Info, text: readCSVObj.name)
91-
9299
}
93100

94101
override func didReceiveMemoryWarning() {

0 commit comments

Comments
 (0)