-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from duytph/master
[Enhancement] [SPM] Bundle Resource
- Loading branch information
Showing
7 changed files
with
89 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
// swift-tools-version:5.0 | ||
// swift-tools-version:5.3 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "DateTimePicker", | ||
platforms: [ | ||
.iOS(.v9), | ||
.iOS(.v10), | ||
], | ||
products: [ | ||
.library(name: "DateTimePicker", targets: ["DateTimePicker"]) | ||
.library( | ||
name: "DateTimePicker", | ||
targets: ["DateTimePicker"]) | ||
], | ||
dependencies: [], | ||
targets: [ | ||
.target(name: "DateTimePicker", path: "Source") | ||
], | ||
swiftLanguageVersions: [.v5] | ||
.target( | ||
name: "DateTimePicker", | ||
path: "Source") | ||
] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Bundle+Resource.swift | ||
// DateTimePicker | ||
// | ||
// Created by Duy Tran on 10/9/20. | ||
// | ||
|
||
import Foundation | ||
|
||
private class MyBundleFinder {} | ||
|
||
extension Foundation.Bundle { | ||
|
||
/** | ||
The resource bundle associated with the current module.. | ||
- important: When `DateTimePicker` is distributed via Swift Package Manager, it will be synthesized automatically in the name of `Bundle.module`. | ||
*/ | ||
static var resource: Bundle = { | ||
let moduleName = "DateTimePicker" | ||
#if COCOAPODS | ||
let bundleName = moduleName | ||
#else | ||
let bundleName = "\(moduleName)_\(moduleName)" | ||
#endif | ||
|
||
let candidates = [ | ||
// Bundle should be present here when the package is linked into an App. | ||
Bundle.main.resourceURL, | ||
|
||
// Bundle should be present here when the package is linked into a framework. | ||
Bundle(for: MyBundleFinder.self).resourceURL, | ||
|
||
// For command-line tools. | ||
Bundle.main.bundleURL, | ||
] | ||
|
||
for candidate in candidates { | ||
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle") | ||
if let bundle = bundlePath.flatMap(Bundle.init(url:)) { | ||
return bundle | ||
} | ||
} | ||
|
||
fatalError("Unable to find bundle named \(bundleName)") | ||
}() | ||
} |
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