Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from Wevah/idna
Browse files Browse the repository at this point in the history
Fix loading of the uts46 file when built as a Swift package
  • Loading branch information
vincode-io authored Jul 31, 2020
2 parents aed4ec0 + 4706274 commit d40861d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "RSWeb",
dependencies: [],
resources: [.copy("UTS46/uts46")]),
resources: [.copy("UTS46/uts46")],
swiftSettings: [.define("SWIFT_PACKAGE")]),
.testTarget(
name: "RSWebTests",
dependencies: ["RSWeb"]),
Expand Down
10 changes: 9 additions & 1 deletion Sources/RSWeb/UTS46/UTS46+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ extension UTS46 {
isLoaded = true
}

static var bundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: Self.self)
#endif
}

static func loadIfNecessary() throws {
guard !isLoaded else { return }
guard let url = Bundle(for: Self.self).url(forResource: "uts46", withExtension: nil) else { throw CocoaError(.fileNoSuchFile) }
guard let url = Self.bundle.url(forResource: "uts46", withExtension: nil) else { throw CocoaError(.fileNoSuchFile) }

try load(from: url)
}
Expand Down

0 comments on commit d40861d

Please sign in to comment.