-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Able to Read the CSV file and convert to CSV class(Object Oriented …
…Approach). - Refactored CSV Export class.
- Loading branch information
1 parent
bc7cf4f
commit 0e2528b
Showing
7 changed files
with
114 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ Simple way to export csv file with rich feature framework and written in Swift. | |
- Able to set CSV headers using fields. | ||
- Able to convert JSON string into CSV. | ||
- Able to Read the CSV file and convert to NSDictionary. | ||
- Able to Read the CSV file and convert to CSV class(Object Oriented Approach). | ||
- Support CocoaPods, mac OS and Vapor framework(Swift Package Manager). | ||
- Able to encoding CSV based on String.Encoding Type(utf8, ascii, unicode, utf16, etc) Refer: String.Encoding. | ||
- Able to view the exported CSV documents in iOS Files app by enabling the configuration in your project. | ||
|
@@ -240,6 +241,53 @@ if fileDetails.allKeys.count > 0 { | |
} | ||
|
||
|
||
``` | ||
|
||
### Example 7 - Swift - Object Oriented Approach | ||
|
||
```swift | ||
|
||
// Generate CSV file | ||
let user1:NSMutableDictionary = NSMutableDictionary() | ||
user1.setObject("vignesh", forKey: "name" as NSCopying); | ||
user1.setObject("[email protected]", forKey: "email" as NSCopying); | ||
user1.setObject("Hi Vignesh, \nhow are you? \t Shall we meet tomorrow? \r Thanks ", forKey: "address" as NSCopying); | ||
|
||
let user2:NSMutableDictionary = NSMutableDictionary() | ||
user2.setObject("vinoth", forKey: "name" as NSCopying); | ||
user2.setObject("[email protected]", forKey: "email" as NSCopying); | ||
user2.setObject("Hi Vinoth, \nHow are you? \t Shall we meet tomorrow? \r Thanks ", forKey: "address" as NSCopying); | ||
|
||
|
||
let data:NSMutableArray = NSMutableArray() | ||
data.add(user1); | ||
data.add(user2); | ||
|
||
// Create a object for write CSV | ||
let writeCSVObj = CSV() | ||
writeCSVObj.rows = data | ||
writeCSVObj.fields = ["name", "email", "address"] | ||
writeCSVObj.name = "userlist" | ||
|
||
// Write File using CSV class object | ||
let filePath:String = SwiftCSVExport.exportCSV(writeCSVObj); | ||
print(filePath) | ||
|
||
// Read File in Object Oriented Way | ||
let readCSVObj = readCSVObject(filePath); | ||
|
||
// Use 'SwiftLoggly' pod framework to print the Dictionary | ||
loggly(LogType.Info, text: readCSVObj.name) | ||
|
||
|
||
``` | ||
|
||
### Write Output: | ||
|
||
```swift | ||
|
||
Output: userlist | ||
|
||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters