Skip to content

Commit a3f38cb

Browse files
authored
Merge pull request #104 from duytph/master
[Enhancement] [SPM] Bundle Resource
2 parents 05b2fc5 + 08aea05 commit a3f38cb

File tree

7 files changed

+89
-35
lines changed

7 files changed

+89
-35
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DateTimePicker.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Pod::Spec.new do |s|
44
#
55

66
s.name = "DateTimePicker"
7-
s.version = "2.4.1"
7+
s.version = "2.5.0"
88
s.summary = "A nicer iOS UI component for picking date and time."
99

1010
s.description = "DateTimePicker makes it easy to select date and time with an attractive looking component."
@@ -50,7 +50,7 @@ Pod::Spec.new do |s|
5050
s.framework = "UIKit"
5151

5252
s.requires_arc = true
53-
s.pod_target_xcconfig = { "SWIFT_VERSION" => "5.0" }
54-
s.swift_version = "5.0"
53+
s.pod_target_xcconfig = { "SWIFT_VERSION" => "5.3" }
54+
s.swift_version = "5.3"
5555

5656
end

DateTimePicker.xcodeproj/project.pbxproj

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
2C788A1D2116AF2E00B26F02 /* FullDateCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8BBF8171F91EAA2005D807B /* FullDateCollectionViewCell.swift */; };
1414
2C788A1E2116AF2E00B26F02 /* StepCollectionViewFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE58808E1D9A5F2E000C93E3 /* StepCollectionViewFlowLayout.swift */; };
1515
2C788A232116AFAD00B26F02 /* DateTimePicker.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C788A222116AFAD00B26F02 /* DateTimePicker.h */; settings = {ATTRIBUTES = (Public, ); }; };
16+
966066EE2530AF7000427563 /* Bundle+Resource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966066ED2530AF7000427563 /* Bundle+Resource.swift */; };
17+
966066EF2530AF7000427563 /* Bundle+Resource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966066ED2530AF7000427563 /* Bundle+Resource.swift */; };
1618
C8BBF8181F91EAA2005D807B /* FullDateCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8BBF8171F91EAA2005D807B /* FullDateCollectionViewCell.swift */; };
1719
DE20B66D23DACE1C009532AE /* DateTimePicker.xib in Resources */ = {isa = PBXBuildFile; fileRef = DE29D3FA23DAC502007CC0F4 /* DateTimePicker.xib */; };
1820
DE20B66F23DAE1E5009532AE /* FullDateCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DE20B66E23DAE1E5009532AE /* FullDateCollectionViewCell.xib */; };
@@ -54,6 +56,7 @@
5456
2C7889C32116AC4900B26F02 /* DateTimePicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DateTimePicker.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5557
2C7889C62116AC4A00B26F02 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5658
2C788A222116AFAD00B26F02 /* DateTimePicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateTimePicker.h; sourceTree = "<group>"; };
59+
966066ED2530AF7000427563 /* Bundle+Resource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bundle+Resource.swift"; sourceTree = "<group>"; };
5760
C8BBF8171F91EAA2005D807B /* FullDateCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullDateCollectionViewCell.swift; sourceTree = "<group>"; };
5861
DE20B66E23DAE1E5009532AE /* FullDateCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FullDateCollectionViewCell.xib; sourceTree = "<group>"; };
5962
DE29D3F223C1B2C1007CC0F4 /* DateTimePicker+UITableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateTimePicker+UITableView.swift"; sourceTree = "<group>"; };
@@ -113,13 +116,14 @@
113116
DEF7C3781D8B9F590043D9C4 /* Source */ = {
114117
isa = PBXGroup;
115118
children = (
119+
966066ED2530AF7000427563 /* Bundle+Resource.swift */,
116120
DEF7C3791D8B9F590043D9C4 /* DateTimePicker.swift */,
117-
C8BBF8171F91EAA2005D807B /* FullDateCollectionViewCell.swift */,
118-
DE58808E1D9A5F2E000C93E3 /* StepCollectionViewFlowLayout.swift */,
119-
DE29D3F223C1B2C1007CC0F4 /* DateTimePicker+UITableView.swift */,
120-
DE29D3F423C1B301007CC0F4 /* DateTimePicker+CollectionView.swift */,
121121
DE29D3FA23DAC502007CC0F4 /* DateTimePicker.xib */,
122+
DE29D3F423C1B301007CC0F4 /* DateTimePicker+CollectionView.swift */,
123+
DE29D3F223C1B2C1007CC0F4 /* DateTimePicker+UITableView.swift */,
124+
C8BBF8171F91EAA2005D807B /* FullDateCollectionViewCell.swift */,
122125
DE20B66E23DAE1E5009532AE /* FullDateCollectionViewCell.xib */,
126+
DE58808E1D9A5F2E000C93E3 /* StepCollectionViewFlowLayout.swift */,
123127
);
124128
path = Source;
125129
sourceTree = SOURCE_ROOT;
@@ -182,7 +186,7 @@
182186
isa = PBXProject;
183187
attributes = {
184188
LastSwiftUpdateCheck = 0730;
185-
LastUpgradeCheck = 1020;
189+
LastUpgradeCheck = 1200;
186190
ORGANIZATIONNAME = ichigo;
187191
TargetAttributes = {
188192
2C7889C22116AC4900B26F02 = {
@@ -248,6 +252,7 @@
248252
2C788A1D2116AF2E00B26F02 /* FullDateCollectionViewCell.swift in Sources */,
249253
2C788A1E2116AF2E00B26F02 /* StepCollectionViewFlowLayout.swift in Sources */,
250254
DE29D3F523C1B301007CC0F4 /* DateTimePicker+CollectionView.swift in Sources */,
255+
966066EF2530AF7000427563 /* Bundle+Resource.swift in Sources */,
251256
);
252257
runOnlyForDeploymentPostprocessing = 0;
253258
};
@@ -260,6 +265,7 @@
260265
DE29D3F723C1B49F007CC0F4 /* DateTimePicker+CollectionView.swift in Sources */,
261266
DE29D3F623C1B49C007CC0F4 /* DateTimePicker+UITableView.swift in Sources */,
262267
DEF7C37A1D8B9F590043D9C4 /* DateTimePicker.swift in Sources */,
268+
966066EE2530AF7000427563 /* Bundle+Resource.swift in Sources */,
263269
);
264270
runOnlyForDeploymentPostprocessing = 0;
265271
};
@@ -293,7 +299,7 @@
293299
GCC_C_LANGUAGE_STANDARD = gnu11;
294300
INFOPLIST_FILE = DateTimePicker/Info.plist;
295301
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
296-
IPHONEOS_DEPLOYMENT_TARGET = 11.4;
302+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
297303
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
298304
PRODUCT_BUNDLE_IDENTIFIER = com.ichigo.DateTimePicker;
299305
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -324,7 +330,7 @@
324330
GCC_C_LANGUAGE_STANDARD = gnu11;
325331
INFOPLIST_FILE = DateTimePicker/Info.plist;
326332
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
327-
IPHONEOS_DEPLOYMENT_TARGET = 11.4;
333+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
328334
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
329335
PRODUCT_BUNDLE_IDENTIFIER = com.ichigo.DateTimePicker;
330336
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -360,6 +366,7 @@
360366
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
361367
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
362368
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
369+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
363370
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
364371
CLANG_WARN_STRICT_PROTOTYPES = YES;
365372
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -384,11 +391,12 @@
384391
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
385392
GCC_WARN_UNUSED_FUNCTION = YES;
386393
GCC_WARN_UNUSED_VARIABLE = YES;
387-
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
394+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
388395
MTL_ENABLE_DEBUG_INFO = YES;
389396
ONLY_ACTIVE_ARCH = YES;
390397
SDKROOT = iphoneos;
391398
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
399+
SWIFT_VERSION = 5.0;
392400
};
393401
name = Debug;
394402
};
@@ -416,6 +424,7 @@
416424
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
417425
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
418426
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
427+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
419428
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
420429
CLANG_WARN_STRICT_PROTOTYPES = YES;
421430
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -434,10 +443,11 @@
434443
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
435444
GCC_WARN_UNUSED_FUNCTION = YES;
436445
GCC_WARN_UNUSED_VARIABLE = YES;
437-
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
446+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
438447
MTL_ENABLE_DEBUG_INFO = NO;
439448
SDKROOT = iphoneos;
440449
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
450+
SWIFT_VERSION = 5.0;
441451
VALIDATE_PRODUCT = YES;
442452
};
443453
name = Release;
@@ -451,7 +461,7 @@
451461
CURRENT_PROJECT_VERSION = 1;
452462
DEVELOPMENT_TEAM = 2L9U9J29G7;
453463
INFOPLIST_FILE = Demo/Info.plist;
454-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
464+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
455465
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
456466
MARKETING_VERSION = 1.0;
457467
PRODUCT_BUNDLE_IDENTIFIER = com.ichigo.DateTimePickerDemo;
@@ -469,7 +479,7 @@
469479
CURRENT_PROJECT_VERSION = 1;
470480
DEVELOPMENT_TEAM = T4WYNJ2VYX;
471481
INFOPLIST_FILE = Demo/Info.plist;
472-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
482+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
473483
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
474484
MARKETING_VERSION = 1.0;
475485
PRODUCT_BUNDLE_IDENTIFIER = com.ichigo.DateTimePickerDemo;

DateTimePicker.xcodeproj/xcshareddata/xcschemes/DateTimePicker.xcscheme

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1200"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -29,8 +29,6 @@
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
3131
</Testables>
32-
<AdditionalOptions>
33-
</AdditionalOptions>
3432
</TestAction>
3533
<LaunchAction
3634
buildConfiguration = "Debug"
@@ -51,8 +49,6 @@
5149
ReferencedContainer = "container:DateTimePicker.xcodeproj">
5250
</BuildableReference>
5351
</MacroExpansion>
54-
<AdditionalOptions>
55-
</AdditionalOptions>
5652
</LaunchAction>
5753
<ProfileAction
5854
buildConfiguration = "Release"

Package.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
// swift-tools-version:5.0
1+
// swift-tools-version:5.3
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33
import PackageDescription
44

55
let package = Package(
66
name: "DateTimePicker",
77
platforms: [
8-
.iOS(.v9),
8+
.iOS(.v10),
99
],
1010
products: [
11-
.library(name: "DateTimePicker", targets: ["DateTimePicker"])
11+
.library(
12+
name: "DateTimePicker",
13+
targets: ["DateTimePicker"])
1214
],
1315
dependencies: [],
1416
targets: [
15-
.target(name: "DateTimePicker", path: "Source")
16-
],
17-
swiftLanguageVersions: [.v5]
17+
.target(
18+
name: "DateTimePicker",
19+
path: "Source")
20+
]
1821
)

Source/Bundle+Resource.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// Bundle+Resource.swift
3+
// DateTimePicker
4+
//
5+
// Created by Duy Tran on 10/9/20.
6+
//
7+
8+
import Foundation
9+
10+
private class MyBundleFinder {}
11+
12+
extension Foundation.Bundle {
13+
14+
/**
15+
The resource bundle associated with the current module..
16+
- important: When `DateTimePicker` is distributed via Swift Package Manager, it will be synthesized automatically in the name of `Bundle.module`.
17+
*/
18+
static var resource: Bundle = {
19+
let moduleName = "DateTimePicker"
20+
#if COCOAPODS
21+
let bundleName = moduleName
22+
#else
23+
let bundleName = "\(moduleName)_\(moduleName)"
24+
#endif
25+
26+
let candidates = [
27+
// Bundle should be present here when the package is linked into an App.
28+
Bundle.main.resourceURL,
29+
30+
// Bundle should be present here when the package is linked into a framework.
31+
Bundle(for: MyBundleFinder.self).resourceURL,
32+
33+
// For command-line tools.
34+
Bundle.main.bundleURL,
35+
]
36+
37+
for candidate in candidates {
38+
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
39+
if let bundle = bundlePath.flatMap(Bundle.init(url:)) {
40+
return bundle
41+
}
42+
}
43+
44+
fatalError("Unable to find bundle named \(bundleName)")
45+
}()
46+
}

Source/DateTimePicker.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,9 @@ public protocol DateTimePickerDelegate: class {
288288
}
289289
}
290290

291-
private static var resourceBundle: Bundle? {
292-
let podBundle = Bundle(for: DateTimePicker.self)
293-
guard let bundleURL = podBundle.url(forResource: "DateTimePicker", withExtension: "bundle") else {
294-
return Bundle.main
295-
}
296-
return Bundle(url: bundleURL)
297-
}
298-
299291
@objc open class func create(minimumDate: Date? = nil, maximumDate: Date? = nil) -> DateTimePicker {
300292

301-
guard let dateTimePicker = resourceBundle?.loadNibNamed("DateTimePicker", owner: nil, options: nil)?.first as? DateTimePicker else {
293+
guard let dateTimePicker = Bundle.resource.loadNibNamed("DateTimePicker", owner: nil, options: nil)?.first as? DateTimePicker else {
302294
fatalError("Error loading nib")
303295
}
304296
dateTimePicker.minimumDate = minimumDate ?? Date(timeIntervalSinceNow: -3600 * 24 * 10)
@@ -418,7 +410,7 @@ public protocol DateTimePickerDelegate: class {
418410
layout.sectionInset = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
419411
layout.itemSize = CGSize(width: 75, height: 80)
420412
}
421-
dayCollectionView.register(UINib(nibName: "FullDateCollectionViewCell", bundle: DateTimePicker.resourceBundle), forCellWithReuseIdentifier: "dateCell")
413+
dayCollectionView.register(UINib(nibName: "FullDateCollectionViewCell", bundle: .resource), forCellWithReuseIdentifier: "dateCell")
422414
dayCollectionView.dataSource = self
423415
dayCollectionView.delegate = self
424416
dayCollectionView.isHidden = isTimePickerOnly

0 commit comments

Comments
 (0)