From c1c1a959c8318de8f56d64c30cbac365782fcc32 Mon Sep 17 00:00:00 2001 From: skipp Date: Tue, 26 Jul 2022 19:16:56 +0700 Subject: [PATCH] Add support swiftpackage --- .gitignore | 1 + Package.swift | 27 +++++++++++++++++++ ScrollableDatepicker.podspec | 4 +-- .../Configuration.swift | 0 .../{ => ScrollableDatepicker}/DayCell.swift | 0 .../LoadableFromXibView.swift | 9 +++++-- .../Resources}/DayCell.xib | 17 ++++++------ .../Resources}/ScrollableDatepicker.xib | 6 +++-- .../ScrollableDatepicker.swift | 11 ++++++-- 9 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 Package.swift rename Sources/{ => ScrollableDatepicker}/Configuration.swift (100%) rename Sources/{ => ScrollableDatepicker}/DayCell.swift (100%) rename Sources/{ => ScrollableDatepicker}/LoadableFromXibView.swift (85%) rename Sources/{ => ScrollableDatepicker/Resources}/DayCell.xib (91%) rename Sources/{ => ScrollableDatepicker/Resources}/ScrollableDatepicker.xib (90%) rename Sources/{ => ScrollableDatepicker}/ScrollableDatepicker.swift (94%) diff --git a/.gitignore b/.gitignore index 4f72d78..9e2fbe0 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ out/ # generated by mpeltonen/sbt-idea plugin .idea_modules/ +.swiftpm/ diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..8bee2cd --- /dev/null +++ b/Package.swift @@ -0,0 +1,27 @@ +// swift-tools-version: 5.6 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "ScrollableDatepicker", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "ScrollableDatepicker", + targets: ["ScrollableDatepicker"]), + ], + 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 this package depends on. + .target( + name: "ScrollableDatepicker", + dependencies: [], + resources: [.process("Resources") + ]), + ] +) diff --git a/ScrollableDatepicker.podspec b/ScrollableDatepicker.podspec index e743aa0..67dca26 100644 --- a/ScrollableDatepicker.podspec +++ b/ScrollableDatepicker.podspec @@ -9,8 +9,8 @@ Pod::Spec.new do |s| s.author = { "Dmitry Ivanenko" => "id.noxt@gmail.com" } s.platform = :ios, "9.0" s.source = { :git => "https://github.com/noxt/ScrollableDatepicker.git", :tag => "#{s.version}" } - s.source_files = "Sources" - s.resource_bundles = { "ScrollableDatepicker" => ["Sources/*.xib"] } + s.source_files = "Sources/ScrollableDatepicker" + s.resource_bundles = { "ScrollableDatepicker" => ["Sources/ScrollableDatepicker/Resources/*.xib"] } s.requires_arc = true end diff --git a/Sources/Configuration.swift b/Sources/ScrollableDatepicker/Configuration.swift similarity index 100% rename from Sources/Configuration.swift rename to Sources/ScrollableDatepicker/Configuration.swift diff --git a/Sources/DayCell.swift b/Sources/ScrollableDatepicker/DayCell.swift similarity index 100% rename from Sources/DayCell.swift rename to Sources/ScrollableDatepicker/DayCell.swift diff --git a/Sources/LoadableFromXibView.swift b/Sources/ScrollableDatepicker/LoadableFromXibView.swift similarity index 85% rename from Sources/LoadableFromXibView.swift rename to Sources/ScrollableDatepicker/LoadableFromXibView.swift index abb9396..4c512c3 100644 --- a/Sources/LoadableFromXibView.swift +++ b/Sources/ScrollableDatepicker/LoadableFromXibView.swift @@ -10,7 +10,6 @@ open class LoadableFromXibView: UIView { @IBOutlet public weak var view: UIView! - // MARK: - Inits override public init(frame: CGRect) { @@ -34,9 +33,15 @@ open class LoadableFromXibView: UIView { if bundlePath != nil { bundle = Bundle(path: bundlePath!) } - + #if SWIFT_PACKAGE + let nib = UINib(nibName: String(describing: type(of: self)), bundle: .module) + view = nib.instantiate(withOwner: self, options: nil).first as? UIView + #else let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle) view = nib.instantiate(withOwner: self, options: nil).first as? UIView + #endif + + addSubview(view) view.translatesAutoresizingMaskIntoConstraints = false diff --git a/Sources/DayCell.xib b/Sources/ScrollableDatepicker/Resources/DayCell.xib similarity index 91% rename from Sources/DayCell.xib rename to Sources/ScrollableDatepicker/Resources/DayCell.xib index 72f22de..bb27e9a 100644 --- a/Sources/DayCell.xib +++ b/Sources/ScrollableDatepicker/Resources/DayCell.xib @@ -1,16 +1,15 @@ - - - - + + - + + - + @@ -21,16 +20,16 @@ - +