Skip to content

Commit f332e6e

Browse files
committed
Able to support Objective-C projects.
1 parent b577900 commit f332e6e

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

Examples/SampleSwift/SampleSwift.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
);
338338
runOnlyForDeploymentPostprocessing = 0;
339339
shellPath = /bin/sh;
340-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
340+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
341341
showEnvVarsInLog = 0;
342342
};
343343
33A400582F818FDFD5E2610C /* [CP] Embed Pods Frameworks */ = {
@@ -367,7 +367,7 @@
367367
);
368368
runOnlyForDeploymentPostprocessing = 0;
369369
shellPath = /bin/sh;
370-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
370+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
371371
showEnvVarsInLog = 0;
372372
};
373373
8523F8CAD25749EA216FAF6D /* [CP] Embed Pods Frameworks */ = {
@@ -442,7 +442,7 @@
442442
);
443443
runOnlyForDeploymentPostprocessing = 0;
444444
shellPath = /bin/sh;
445-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
445+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
446446
showEnvVarsInLog = 0;
447447
};
448448
/* End PBXShellScriptBuildPhase section */

SwiftCSVExport.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "SwiftCSVExport"
19-
s.version = "1.0.2"
20-
s.summary = "Simple way to export csv file with rich feature framework in Swift."
19+
s.version = "1.0.3"
20+
s.summary = "Simple way to export csv file with rich feature framework and written in Swift 3."
2121

2222
# This description is used to generate tags and improve search results.
2323
# * Think: What does it do? Why did you write it? What is the focus?

SwiftCSVExport/Sources/CSVExport.swift

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension String {
1616
}
1717

1818
//MARK: - CSVExport Class
19-
open class CSVExport {
19+
@objc open class CSVExport:NSObject {
2020

2121
///The directory in which the cvs files will be written
2222
open var directory = CSVExport.defaultDirectory();
@@ -37,9 +37,19 @@ open class CSVExport {
3737
return Static.instance
3838
}
3939

40+
///a free function to make read the CSV file
41+
open func readCSV(_ filePath:String) -> NSMutableDictionary{
42+
return CSVExport.export.read(filepath: filePath);
43+
}
44+
45+
///a free function to make read the CSV file
46+
open func readCSVFromDefaultPath(_ fileName:String) -> NSMutableDictionary{
47+
return CSVExport.export.read(filename: fileName);
48+
}
49+
4050
///write content to the current csv file.
4151
open func getFilePath() -> String{
42-
let path = "\(directory)/\(csvFileName())"
52+
let path = "\(directory)/\(self.csvFileName())"
4353
let fileManager = FileManager.default
4454
if !fileManager.fileExists(atPath: path) {
4555
return "";
@@ -65,11 +75,31 @@ open class CSVExport {
6575
}
6676
return "";
6777
}
78+
79+
///a free function to make export the CSV file from file name, fields and values
80+
open func exportCSVString(_ filename:String, fields: [String], values: String) -> String{
81+
82+
// Convert String into NSArray of objects.
83+
if let data = (values as NSString).data(using: CSVExport.export.encodingType.rawValue)
84+
{
85+
do {
86+
let parsedObject = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableLeaves) as! NSArray
87+
if parsedObject.count > 0
88+
{
89+
return CSVExport.export.exportCSV(filename, fields: fields as NSArray, values: parsedObject);
90+
}
91+
} catch {
92+
print("error handling...\(error)")
93+
return "";
94+
}
95+
}
96+
return "";
97+
}
6898

6999

70100
///write content to the current csv file.
71101
open func write(text: String) {
72-
let path = "\(directory)/\(csvFileName())"
102+
let path = "\(directory)/\(self.csvFileName())"
73103
let fileManager = FileManager.default
74104
if !fileManager.fileExists(atPath: path) {
75105
do {
@@ -170,11 +200,11 @@ open class CSVExport {
170200

171201
///do the checks and cleanup
172202
open func cleanup() {
173-
let path = "\(directory)/\(csvFileName())"
174-
let size = fileSize(path)
203+
let path = "\(directory)/\(self.csvFileName())"
204+
let size = self.fileSize(path)
175205
if size > 0 {
176206
//delete the oldest file
177-
let deletePath = "\(directory)/\(csvFileName())"
207+
let deletePath = "\(directory)/\(self.csvFileName())"
178208
let fileManager = FileManager.default
179209
do {
180210
try fileManager.removeItem(atPath: deletePath)
@@ -184,7 +214,7 @@ open class CSVExport {
184214
}
185215

186216
///check the size of a file
187-
func fileSize(_ path: String) -> UInt64 {
217+
open func fileSize(_ path: String) -> UInt64 {
188218
let fileManager = FileManager.default
189219
if fileManager.fileExists(atPath: path) {
190220
let attrs: NSDictionary? = try! fileManager.attributesOfItem(atPath: path) as NSDictionary?
@@ -255,32 +285,17 @@ public func exportCSV(_ filename:String, fields: [String], values: [[String:Any]
255285

256286
///a free function to make export the CSV file from file name, fields and values
257287
public func exportCSV(_ filename:String, fields: [String], values: String) -> String{
258-
259-
// Convert String into NSArray of objects.
260-
if let data = (values as NSString).data(using: CSVExport.export.encodingType.rawValue)
261-
{
262-
do {
263-
let parsedObject = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableLeaves) as! NSArray
264-
if parsedObject.count > 0
265-
{
266-
return CSVExport.export.exportCSV(filename, fields: fields as NSArray, values: parsedObject);
267-
}
268-
} catch {
269-
print("error handling...\(error)")
270-
return "";
271-
}
272-
}
273-
return "";
288+
return CSVExport.export.exportCSVString(filename, fields: (fields as NSArray) as! [String], values: values);
274289
}
275290

276291
///a free function to make read the CSV file
277292
public func readCSV(_ filePath:String) -> NSMutableDictionary{
278-
return CSVExport.export.read(filepath: filePath);
293+
return CSVExport.export.readCSV(filePath);
279294
}
280295

281296
///a free function to make read the CSV file
282297
public func readCSVFromDefaultPath(_ fileName:String) -> NSMutableDictionary{
283-
return CSVExport.export.read(filename: fileName);
298+
return CSVExport.export.readCSVFromDefaultPath(fileName);
284299
}
285300

286301

0 commit comments

Comments
 (0)