Skip to content

Commit eae3fdb

Browse files
committed
Updated SPM support.
1 parent 83342e0 commit eae3fdb

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

DateTools/DateTools/NSDate+DateTools.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222

2323
#ifndef DateToolsLocalizedStrings
24+
25+
#ifdef SPM
26+
#define DateToolsLocalizedStrings(key) \
27+
NSLocalizedStringFromTableInBundle(key, @"DateTools", [NSBundle bundleWithPath:[[SWIFTPM_MODULE_BUNDLE resourcePath] stringByAppendingPathComponent:@"DateTools.bundle"]], nil)
28+
#else
2429
#define DateToolsLocalizedStrings(key) \
2530
NSLocalizedStringFromTableInBundle(key, @"DateTools", [NSBundle bundleWithPath:[[[NSBundle bundleForClass:[DTError class]] resourcePath] stringByAppendingPathComponent:@"DateTools.bundle"]], nil)
2631
#endif
2732

33+
#endif
34+
2835
#import <Foundation/Foundation.h>
2936
#import "DTConstants.h"
3037

DateToolsSwift/DateTools/Date+Bundle.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@
99
import Foundation
1010

1111
public extension Bundle {
12-
13-
class func dateToolsBundle() -> Bundle {
14-
let assetPath = Bundle(for: Constants.self).resourcePath!
15-
return Bundle(path: NSString(string: assetPath).appendingPathComponent("DateTools.bundle"))!
16-
}
12+
13+
class func dateToolsBundle() -> Bundle? {
14+
let assetPath: String?
15+
#if SPM
16+
assetPath = Bundle.module.resourcePath
17+
#else
18+
assetPath = Bundle(for: Constants.self).resourcePath
19+
#endif
20+
guard let assetPath = assetPath else { return nil }
21+
return Bundle(path: NSString(string: assetPath).appendingPathComponent("DateTools.bundle"))
22+
}
23+
1724
}
1825

DateToolsSwift/DateTools/Date+TimeAgo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public extension Date {
243243
// However, a seemingly-equivalent method from NSBundle is: https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSBundle.swift
244244
return Bundle.main.localizedString(forKey: string, value: "", table: "DateTools")
245245
#else
246-
return NSLocalizedString(string, tableName: "DateTools", bundle: Bundle.dateToolsBundle(), value: "", comment: "")
246+
return NSLocalizedString(string, tableName: "DateTools", bundle: Bundle.dateToolsBundle() ?? .main, value: "", comment: "")
247247
#endif
248248
}
249249

Package.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
1+
// swift-tools-version:5.3
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
13
import PackageDescription
24

35
let package = Package(
46
name: "DateToolsSwift",
7+
defaultLocalization: "en",
8+
platforms: [
9+
.iOS(.v12),
10+
.tvOS(.v12),
11+
.macOS(.v10_13),
12+
],
13+
products: [
14+
.library(name: "DateToolsSwift", targets: ["DateToolsSwift"]),
15+
.library(name: "DateToolsObjc", targets: ["DateToolsObjc"])
16+
],
17+
dependencies: [
18+
],
519
targets: [
6-
Target(name: "DateToolsSwift")
20+
.target(
21+
name: "DateToolsSwift",
22+
path: "DateToolsSwift/DateTools",
23+
resources: [.copy("DateTools.bundle")],
24+
swiftSettings: [.define("SPM")]
25+
),
26+
.target(
27+
name: "DateToolsObjc",
28+
path: "DateTools/DateTools",
29+
resources: [.copy("DateTools.bundle")],
30+
publicHeadersPath: ".",
31+
cSettings: [.define("SPM")]
32+
)
733
]
834
)
9-
package.exclude = ["DateTools", "Examples", "Tests", "DateToolsSwift/Examples"]
35+
36+

0 commit comments

Comments
 (0)