diff --git a/.gitignore b/.gitignore index 442bdb8..9f5ae1c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ DerivedData *.hmap *.ipa *.xcuserstate +.build/ # CocoaPods # diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..90f685f --- /dev/null +++ b/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version:5.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "SwiftCSV", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "SwiftCSV", + targets: ["SwiftCSV"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "SwiftCSV", + path: "SwiftCSV"), + .testTarget( + name: "SwiftCSVTests", + dependencies: ["SwiftCSV"], + path: "SwiftCSVTests"), + ] +) diff --git a/SwiftCSV.xcodeproj/project.pbxproj b/SwiftCSV.xcodeproj/project.pbxproj index 6cf1959..8222c91 100644 --- a/SwiftCSV.xcodeproj/project.pbxproj +++ b/SwiftCSV.xcodeproj/project.pbxproj @@ -65,6 +65,9 @@ BEE5461E1CBBB15900C0666F /* Description.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEE5461D1CBBB15900C0666F /* Description.swift */; }; E46085921CCB1E8F00385286 /* large.csv in Resources */ = {isa = PBXBuildFile; fileRef = E46085911CCB1E8F00385286 /* large.csv */; }; E46085941CCB1F5C00385286 /* PerformanceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E46085931CCB1F5C00385286 /* PerformanceTest.swift */; }; + F5C19F502283243C00920B06 /* ResourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5C19F4F2283243C00920B06 /* ResourceHelper.swift */; }; + F5C19F512283C0C100920B06 /* ResourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5C19F4F2283243C00920B06 /* ResourceHelper.swift */; }; + F5C19F522283C0C300920B06 /* ResourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F5C19F4F2283243C00920B06 /* ResourceHelper.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -124,6 +127,7 @@ BEE5461D1CBBB15900C0666F /* Description.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Description.swift; sourceTree = ""; }; E46085911CCB1E8F00385286 /* large.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = large.csv; sourceTree = ""; }; E46085931CCB1F5C00385286 /* PerformanceTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTest.swift; sourceTree = ""; }; + F5C19F4F2283243C00920B06 /* ResourceHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResourceHelper.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -243,6 +247,7 @@ BE06B67C1CB7267B009578CC /* empty_fields.csv */, BE06B6811CB7287F009578CC /* quotes.csv */, E46085911CCB1E8F00385286 /* large.csv */, + F5C19F4F2283243C00920B06 /* ResourceHelper.swift */, ); name = Res; sourceTree = ""; @@ -558,6 +563,7 @@ files = ( E46085941CCB1F5C00385286 /* PerformanceTest.swift in Sources */, 3D1E59C71945FFAD001CF760 /* CSVTests.swift in Sources */, + F5C19F502283243C00920B06 /* ResourceHelper.swift in Sources */, 508975E11DBF3E51006F3DBE /* EnumeratedViewTests.swift in Sources */, 3D3749E3194D6DF7008F262A /* TSVTests.swift in Sources */, BE06B6801CB726B5009578CC /* URLTests.swift in Sources */, @@ -585,6 +591,7 @@ files = ( 5FB74BE01CCB9312009DDBF1 /* CSVTests.swift in Sources */, 5FB74BE11CCB9312009DDBF1 /* QuotedTests.swift in Sources */, + F5C19F512283C0C100920B06 /* ResourceHelper.swift in Sources */, 508975E21DBF3E51006F3DBE /* EnumeratedViewTests.swift in Sources */, 5FB74BE21CCB9312009DDBF1 /* TSVTests.swift in Sources */, 5FB74BE31CCB9312009DDBF1 /* URLTests.swift in Sources */, @@ -612,6 +619,7 @@ files = ( 5FB74BE51CCB931F009DDBF1 /* CSVTests.swift in Sources */, 5FB74BE61CCB931F009DDBF1 /* QuotedTests.swift in Sources */, + F5C19F522283C0C300920B06 /* ResourceHelper.swift in Sources */, 508975E31DBF3E51006F3DBE /* EnumeratedViewTests.swift in Sources */, 5FB74BE71CCB931F009DDBF1 /* TSVTests.swift in Sources */, 5FB74BE81CCB931F009DDBF1 /* URLTests.swift in Sources */, diff --git a/SwiftCSVTests/PerformanceTest.swift b/SwiftCSVTests/PerformanceTest.swift index 6eb8a27..1465f3e 100644 --- a/SwiftCSVTests/PerformanceTest.swift +++ b/SwiftCSVTests/PerformanceTest.swift @@ -13,7 +13,7 @@ class PerformanceTest: XCTestCase { var csv: CSV! override func setUp() { - let csvURL = Bundle(for: CSVTests.self).url(forResource: "large", withExtension: "csv")! + let csvURL = ResourceHelper.url(forResource: "large", withExtension: "csv")! csv = try! CSV(url: csvURL) } diff --git a/SwiftCSVTests/ResourceHelper.swift b/SwiftCSVTests/ResourceHelper.swift new file mode 100644 index 0000000..663de93 --- /dev/null +++ b/SwiftCSVTests/ResourceHelper.swift @@ -0,0 +1,16 @@ +import Foundation + +// Find url of resource. +// This is a workaround for SwiftPM, becasue SwiftPM is not yet support for include resources with targets.(https://bugs.swift.org/browse/SR-2866) +struct ResourceHelper { + static func url(forResource name: String, withExtension type: String) -> URL? { + let bundle = Bundle(for: CSVTests.self) + if let url = bundle.url(forResource: name, withExtension: type) { + return url + } else if let realBundle = Bundle(path: "\(bundle.bundlePath)/../../../../SwiftCSVTests") { + return realBundle.url(forResource: name, withExtension: type) + } else { + return nil + } + } +} diff --git a/SwiftCSVTests/URLTests.swift b/SwiftCSVTests/URLTests.swift index 6fac691..aaaddf9 100644 --- a/SwiftCSVTests/URLTests.swift +++ b/SwiftCSVTests/URLTests.swift @@ -13,7 +13,7 @@ class URLTests: XCTestCase { var csv: CSV! func testEmptyFields() { - let csvURL = Bundle(for: CSVTests.self).url(forResource: "empty_fields", withExtension: "csv")! + let csvURL = ResourceHelper.url(forResource: "empty_fields", withExtension: "csv")! csv = try! CSV(url: csvURL) let expected = [ ["id": "1", "name": "John", "age": "23"], @@ -29,7 +29,7 @@ class URLTests: XCTestCase { } func testQuotes() { - let csvURL = Bundle(for: CSVTests.self).url(forResource: "quotes", withExtension: "csv")! + let csvURL = ResourceHelper.url(forResource: "quotes", withExtension: "csv")! csv = try! CSV(url: csvURL) let expected = [ ["id": "4", "name, first": "Alex", "name, last": "Smith"],