-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.html
executable file
·280 lines (240 loc) · 15.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="apple-touch-icon" sizes="57x57" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="https://vigneshuvi.github.io/favicon.ico/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="https://vigneshuvi.github.io/favicon.ico/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="https://vigneshuvi.github.io/favicon.ico/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="https://vigneshuvi.github.io/favicon.ico/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://vigneshuvi.github.io/favicon.ico/favicon-16x16.png">
<link rel="shortcut icon" type="image/x-icon" href="https://vigneshuvi.github.io/favicon.ico?">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="https://vigneshuvi.github.io/favicon.ico/ms-icon-144x144.png">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Swift CSV Export">
<meta name="author" content="Vignesh">
<title>Vignesh Kumar - Swift CSV Export Blog</title>
<!-- Bootstrap Core CSS -->
<link href="https://vigneshuvi.github.io/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Theme CSS -->
<link href="https://vigneshuvi.github.io/css/clean-blog.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="https://vigneshuvi.github.io/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
Menu <i class="fa fa-bars"></i>
</button>
<a class="navbar-brand" href="http://vigneshuvi.github.io/">Vigneshuvi</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="http://vigneshuvi.github.io/">Home</a>
</li>
<li>
<a href="http://vigneshuvi.github.io/">About</a>
</li>
<li>
<a href="http://vigneshuvi.github.io/">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Header -->
<!-- Set your background image for this header on the line below. -->
<header class="intro-header" style="background-image: url('https://vigneshuvi.github.io/img/home-bg.jpg')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-heading">
<h1>Swift CSV Export</h1>
<h2 class="subheading">Simple way to export csv file with rich feature framework in Swift.</h2>
<span class="meta">Posted by <a href="http://vigneshuvi.github.io/">Vigneshuvi</a> on January 18, 2017</span>
</div>
</div>
</div>
</div>
</header>
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<h2 class="section-heading">Features</h2>
<p>Framework with major highlights</p>
<blockquote>
<ul class="a">
<li>Able to give CSV file name.</li>
<li>Able to set CSV headers using fields.</li>
<li>Able to convert JSON string into CSV.</li>
<li>Able to Read the CSV file and convert to NSDictionary.</li>
<li>Support CocoaPods, mac OS and Vapor framework(Swift Package Manager).</li>
</ul>
</blockquote>
<h2 class="section-heading">iOS/MacOS import headers</h2>
<p>First thing is to import the framework. See the Installation instructions on how to add the framework to your project.</p>
<blockquote>
<span>// iOS</span><br/>
<span>import SwiftCSVExport</span><br/>
</br><br/>
<span>// macOS</span><br/>
<span>import SwiftCSVExportOSX</span><br/>
</blockquote>
<h2 class="section-heading">Examples</h2>
</br>
<h4>Example 1 - Able to convert NSMutableDictionary into CSV</h4>
<blockquote>
<span>// First User Object</span><br/>
<span>let user1:NSMutableDictionary = NSMutableDictionary()</span><br/>
<span>user1.setObject("vignesh", forKey: "name" as NSCopying);</span><br/>
<span>user1.setObject("[email protected]", forKey: "email" as NSCopying);</span><br/><br/>
<span>// Secound User Object</span><br/>
<span>let user1:NSMutableDictionary = NSMutableDictionary()</span><br/>
<span>user1.setObject("vinoth", forKey: "name" as NSCopying);</span><br/>
<span>user1.setObject("[email protected]", forKey: "email" as NSCopying);</span><br/><br/>
<span>// Add fields into columns of CSV headers</span><br/>
<span>let fields:NSMutableArray = NSMutableArray()</span><br/>
<span>fields.add("name");</span><br/>
<span>fields.add("email");</span><br/><br/>
<span>// Add dictionary into rows of CSV Array</span><br/>
<span>let data:NSMutableArray = NSMutableArray()</span><br/>
<span>data.add(user1);</span><br/>
<span>data.add(user2);</span><br/><br/>
<span>let filePath:String = SwiftCSVExport.exportCSV("userlist",fields: fields,values: data);</span><br/>
<span>print(filePath)</span><br/>
</blockquote>
</br>
<h4>Write Output</h4>
<p>Output: userlist.csv</p>
<blockquote>
<span>name,email</span><br/>
<span>vignesh,[email protected]</span><br/>
<span>vinoth,[email protected]</span><br/><br/>
</blockquote>
</br>
<h4>Example 2 - Able to convert JSON string into CSV.</h4>
<blockquote>
<span>// Able to convert JSON string into CSV.</span><br/>
<span>let string = "[{\"name\":\"vignesh\",\"email\":\"[email protected]\"},{\"name\":\"vinoth\",\"email\":\"[email protected]\"}]";</span><br/>
<span>let filePath:String = exportCSV("userlist", fields:["name","email"], values:string);</span><br/>
<span>print(filePath)</span><br/><br/>
<span>// Read File</span><br/>
<span>let fileDetails = readCSV(filePath);</span><br/>
<span>// Use 'SwiftLoggly' pod framework to print the Dictionary/span><br/>
<span>if fileDetails.allKeys.count > 0 {</span><br/>
<span>loggly(LogType.Info, dictionary: fileDetails)</span><br/>
<span>}</span><br/>
</blockquote>
<h4>Read Output</h4>
<blockquote>
<span>[💙 Info - Feb 7, 2017, 4:19:23 PM]: { </span><br/>
<span>"rows" : [ { "name" : "vignesh", "email" : "[email protected]" },</span><br/>
<span>{"name" : "vinoth", "email" : "[email protected]" } ],</span><br/>
<span>"name" : "userlist.csv",</span><br/>
<span>"fields" : ["name", "email"] }</span><br/>
</blockquote>
</br>
<p>That will create a CSV file in the proper directory on both OS X and iOS. </p>
<p>OS X CSV files will be created in the OS X Exports directory (found under: /Library/Exports). The iOS CSV files will be created in your apps document directory under a folder called Exports.</p>
<h2 class="section-heading">Configuration</h2>
<br/>
<blockquote>
<span>//Set the name of the csv file</span><br/>
<span>CSVExport.export.fileName = "Sample" //default is "csvfile"</span><br/><br/>
<span>//Set the directory in which the csv files will be written</span><br/>
<span>CSVExport.export.directory = "/Library/XXX-folder-name-XXX" //default is the standard exporting directory for each platform.</span><br/>
</blockquote>
<h2 class="section-heading">Installation</h2>
<p>CocoaPods - To use SwiftCSVExport in your project add the following 'Podfile' to your project </p>
<blockquote>
<span>platform :ios, '8.0'</span><br/>
<span>use_frameworks!</span><br/>
<span>pod 'SwiftCSVExport'</span><br/><br/>
<span>Then run:</span><br/>
<span>pod install || pod update</span><br/>
</blockquote>
<h2 class="section-heading">Swift Package Manager for Vapor</h2>
<p>You need to add to dependencies in your 'Package.swift' and fetch Swift module using terminal comment.</p>
<blockquote>
<span>// Vapor</span><br/>
<span>dependencies: [ .Package(url: "https://github.com/vigneshuvi/SwiftCSVExport.git", majorVersion: 1, minor: 0) ]</span><br/><br/>
<span>Then run:</span><br/>
<span>vapor build || vapor xcode </span><br/><br/>
<span>// Importing header</span><br/>
<span>import SwiftCSVExport</span><br/>
</blockquote>
<h2 class="section-heading">License</h2>
<p>SwiftCSVExport is licensed under the MIT License.</p>
<p>Source available here!! <a href="https://github.com/vigneshuvi/SwiftCSVExport">SwiftCSVExport</a> </p>
</div>
</div>
</div>
</article>
<hr>
<!-- Footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<ul class="list-inline text-center">
<li>
<a data-toggle="tooltip" title="Facebook" href="https://facebook.com/vigneshuvi" target="_blank" class="social"><img src="https://vigneshuvi.github.io/img/ic_fb.png" width="36" height="36" draggable="false"></a>
</li>
<li>
<a data-toggle="tooltip" title="Stack Overflow" href="http://stackoverflow.com/users/2586904/vignesh-kumar?tab=profile" target="_blank" class="social "><img src="https://vigneshuvi.github.io/img/ic_so.png" width="36" height="36" draggable="false"></a>
</li>
<li>
<a data-toggle="tooltip" title="LinkedIn" href="https://www.linkedin.com/in/vignesh-kumar-62a35254" target="_blank" class="social"><img src="https://vigneshuvi.github.io/img/ic_li.png" width="36" height="36" draggable="false"></a>
</li>
<li>
<a data-toggle="tooltip" title="GitHub" href="https://github.com/vigneshuvi" target="_blank" class="social"><img src="https://vigneshuvi.github.io/img/ic_git.png" width="36" height="36" draggable="false"></a>
</li>
<li>
<a data-toggle="tooltip" title="Skype" href="skype:vignesh.uvi?call" target="_blank" class="social"><img src="https://vigneshuvi.github.io/img/ic_skype.png" width="36" height="36" draggable="false"></a>
</li>
</ul>
<p class="copyright text-muted">Copyright © Vignesh 2016</p>
</div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="https://vigneshuvi.github.io/vendor/jquery/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="https://vigneshuvi.github.io/vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Contact Form JavaScript -->
<script src="https://vigneshuvi.github.io/js/jqBootstrapValidation.js"></script>
<script src="https://vigneshuvi.github.io/js/contact_me.js"></script>
<!-- Theme JavaScript -->
<script src="https://vigneshuvi.github.io/js/clean-blog.min.js"></script>
</body>
</html>