From 9dc96ea62500719ae4c0afd1d27316f21a288473 Mon Sep 17 00:00:00 2001 From: Richard Topchii Date: Tue, 18 Feb 2020 23:13:28 +0200 Subject: [PATCH] Update access modifiers of the API #242 --- .../CalendarApp.xcodeproj/project.pbxproj | 4 ++ .../TimeChunk+DateComponents.swift | 20 ++++++++++ Source/Extensions/Date+AddChunk.swift | 4 +- .../Extensions/TimeChunk+DateComponents.swift | 14 +++---- Source/Header/DayHeaderView.swift | 33 ++++++++--------- Source/Header/DaySelector/DateLabel.swift | 22 +++++------ Source/Header/DaySelector/DayDateCell.swift | 28 +++++++------- Source/Header/DaySelector/DaySelector.swift | 37 +++++++++---------- .../DaySelector/DaySelectorController.swift | 16 ++++---- Source/Header/DaySymbolsView.swift | 23 ++++++------ Source/Header/SwipeLabelView.swift | 31 ++++++++-------- 11 files changed, 126 insertions(+), 106 deletions(-) create mode 100644 CalendarKitDemo/CalendarApp/TimeChunk+DateComponents.swift diff --git a/CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj b/CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj index 92f7e169..6daa5fa9 100644 --- a/CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj +++ b/CalendarKitDemo/CalendarApp.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 75776AF58133F6BBDDCF1CE7 /* Pods_CalendarApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A223D8E39EB8C7A25F4E823A /* Pods_CalendarApp.framework */; }; + 791ACF5023FC887D00B2D602 /* TimeChunk+DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */; }; 7924834B23CB7B57003E3D27 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7924834923CB7B57003E3D27 /* Main.storyboard */; }; 7924834D23CB7B58003E3D27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7924834C23CB7B58003E3D27 /* Assets.xcassets */; }; 7924835023CB7B58003E3D27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7924834E23CB7B58003E3D27 /* LaunchScreen.storyboard */; }; @@ -21,6 +22,7 @@ /* Begin PBXFileReference section */ 786F0C3439DCA027A1D04664 /* Pods-CalendarApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CalendarApp.release.xcconfig"; path = "Target Support Files/Pods-CalendarApp/Pods-CalendarApp.release.xcconfig"; sourceTree = ""; }; + 791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeChunk+DateComponents.swift"; sourceTree = ""; }; 7924834023CB7B57003E3D27 /* CalendarApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CalendarApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 7924834A23CB7B57003E3D27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 7924834C23CB7B58003E3D27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -79,6 +81,7 @@ isa = PBXGroup; children = ( 7924836523CB7BFE003E3D27 /* AppDelegate.swift */, + 791ACF4F23FC887D00B2D602 /* TimeChunk+DateComponents.swift */, 7924836623CB7BFE003E3D27 /* CustomCalendarExampleController.swift */, 7924836423CB7BFE003E3D27 /* DatePickerController.swift */, 7924836723CB7BFE003E3D27 /* ExampleController.swift */, @@ -220,6 +223,7 @@ 7924836E23CB7BFE003E3D27 /* ExampleNotificationController.swift in Sources */, 7924836C23CB7BFE003E3D27 /* CustomCalendarExampleController.swift in Sources */, 7924836923CB7BFE003E3D27 /* StyleGenerator.swift in Sources */, + 791ACF5023FC887D00B2D602 /* TimeChunk+DateComponents.swift in Sources */, 7924836D23CB7BFE003E3D27 /* ExampleController.swift in Sources */, 7924836A23CB7BFE003E3D27 /* DatePickerController.swift in Sources */, ); diff --git a/CalendarKitDemo/CalendarApp/TimeChunk+DateComponents.swift b/CalendarKitDemo/CalendarApp/TimeChunk+DateComponents.swift new file mode 100644 index 00000000..d69998fe --- /dev/null +++ b/CalendarKitDemo/CalendarApp/TimeChunk+DateComponents.swift @@ -0,0 +1,20 @@ +import Foundation +import DateToolsSwift + +extension TimeChunk { + static func dateComponents(seconds: Int = 0, + minutes: Int = 0, + hours: Int = 0, + days: Int = 0, + weeks: Int = 0, + months: Int = 0, + years: Int = 0) -> TimeChunk { + return TimeChunk(seconds: seconds, + minutes: minutes, + hours: hours, + days: days, + weeks: weeks, + months: months, + years: years) + } +} diff --git a/Source/Extensions/Date+AddChunk.swift b/Source/Extensions/Date+AddChunk.swift index d0512589..e2132481 100644 --- a/Source/Extensions/Date+AddChunk.swift +++ b/Source/Extensions/Date+AddChunk.swift @@ -13,7 +13,7 @@ extension Date { * - returns: A date with components increased by the values of the * corresponding `TimeChunk` variables */ - public func add(_ chunk: TimeChunk, calendar: Calendar) -> Date { + func add(_ chunk: TimeChunk, calendar: Calendar) -> Date { var components = DateComponents() components.year = chunk.years components.month = chunk.months @@ -33,7 +33,7 @@ extension Date { * - returns: A date with components decreased by the values of the * corresponding `TimeChunk` variables */ - public func subtract(_ chunk: TimeChunk, calendar: Calendar) -> Date { + func subtract(_ chunk: TimeChunk, calendar: Calendar) -> Date { var components = DateComponents() components.year = -chunk.years components.month = -chunk.months diff --git a/Source/Extensions/TimeChunk+DateComponents.swift b/Source/Extensions/TimeChunk+DateComponents.swift index bd57d102..61f39994 100644 --- a/Source/Extensions/TimeChunk+DateComponents.swift +++ b/Source/Extensions/TimeChunk+DateComponents.swift @@ -2,13 +2,13 @@ import Foundation import DateToolsSwift extension TimeChunk { - public static func dateComponents(seconds: Int = 0, - minutes: Int = 0, - hours: Int = 0, - days: Int = 0, - weeks: Int = 0, - months: Int = 0, - years: Int = 0) -> TimeChunk { + static func dateComponents(seconds: Int = 0, + minutes: Int = 0, + hours: Int = 0, + days: Int = 0, + weeks: Int = 0, + months: Int = 0, + years: Int = 0) -> TimeChunk { return TimeChunk(seconds: seconds, minutes: minutes, hours: hours, diff --git a/Source/Header/DayHeaderView.swift b/Source/Header/DayHeaderView.swift index 3c848be6..6c3d8894 100644 --- a/Source/Header/DayHeaderView.swift +++ b/Source/Header/DayHeaderView.swift @@ -1,13 +1,12 @@ import UIKit import DateToolsSwift -public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, UIPageViewControllerDataSource, UIPageViewControllerDelegate { - - public var daysInWeek = 7 +public final class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, UIPageViewControllerDataSource, UIPageViewControllerDelegate { + public private(set) var daysInWeek = 7 public let calendar: Calendar - var style = DayHeaderStyle() - var currentSizeClass = UIUserInterfaceSizeClass.compact + private var style = DayHeaderStyle() + private var currentSizeClass = UIUserInterfaceSizeClass.compact public weak var state: DayViewState? { willSet(newValue) { @@ -19,17 +18,17 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U } } - var currentWeekdayIndex = -1 + private var currentWeekdayIndex = -1 - var daySymbolsViewHeight: CGFloat = 20 - var pagingScrollViewHeight: CGFloat = 40 - var swipeLabelViewHeight: CGFloat = 20 + private var daySymbolsViewHeight: CGFloat = 20 + private var pagingScrollViewHeight: CGFloat = 40 + private var swipeLabelViewHeight: CGFloat = 20 - let daySymbolsView: DaySymbolsView - var pagingViewController = UIPageViewController(transitionStyle: .scroll, + private let daySymbolsView: DaySymbolsView + private var pagingViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil) - let swipeLabelView: SwipeLabelView + private let swipeLabelView: SwipeLabelView public init(calendar: Calendar) { self.calendar = calendar @@ -45,13 +44,13 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U fatalError("init(coder:) has not been implemented") } - func configure() { + private func configure() { [daySymbolsView, swipeLabelView].forEach(addSubview) backgroundColor = style.backgroundColor configurePagingViewController() } - func configurePagingViewController() { + private func configurePagingViewController() { let selectedDate = Date() let vc = makeSelectorController(startDate: beginningOfWeek(selectedDate)) vc.selectedDate = selectedDate @@ -62,7 +61,7 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U addSubview(pagingViewController.view!) } - func makeSelectorController(startDate: Date) -> DaySelectorController { + private func makeSelectorController(startDate: Date) -> DaySelectorController { let new = DaySelectorController() new.calendar = calendar new.transitionToHorizontalSizeClass(currentSizeClass) @@ -72,7 +71,7 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U return new } - func beginningOfWeek(_ date: Date) -> Date { + private func beginningOfWeek(_ date: Date) -> Date { let weekOfYear = component(component: .weekOfYear, from: date) let yearForWeekOfYear = component(component: .yearForWeekOfYear, from: date) return calendar.date(from: DateComponents(calendar: calendar, @@ -108,7 +107,7 @@ public class DayHeaderView: UIView, DaySelectorDelegate, DayViewStateUpdating, U // MARK: DaySelectorDelegate - func dateSelectorDidSelectDate(_ date: Date) { + public func dateSelectorDidSelectDate(_ date: Date) { state?.move(to: date) } diff --git a/Source/Header/DaySelector/DateLabel.swift b/Source/Header/DaySelector/DateLabel.swift index 281730f2..b148bf22 100644 --- a/Source/Header/DaySelector/DateLabel.swift +++ b/Source/Header/DaySelector/DateLabel.swift @@ -1,14 +1,14 @@ import UIKit import DateToolsSwift -class DateLabel: UILabel, DaySelectorItemProtocol { - var calendar = Calendar.autoupdatingCurrent { +public final class DateLabel: UILabel, DaySelectorItemProtocol { + public var calendar = Calendar.autoupdatingCurrent { didSet { updateState() } } - var date = Date() { + public var date = Date() { didSet { text = String(date.day) updateState() @@ -19,15 +19,15 @@ class DateLabel: UILabel, DaySelectorItemProtocol { return calendar.isDateInToday(date) } - var selected: Bool = false { + public var selected: Bool = false { didSet { animate() } } - var style = DaySelectorStyle() + private var style = DaySelectorStyle() - override var intrinsicContentSize: CGSize { + override public var intrinsicContentSize: CGSize { return CGSize(width: 35, height: 35) } @@ -41,13 +41,13 @@ class DateLabel: UILabel, DaySelectorItemProtocol { configure() } - func configure() { + private func configure() { isUserInteractionEnabled = true textAlignment = .center clipsToBounds = true } - func updateStyle(_ newStyle: DaySelectorStyle) { + public func updateStyle(_ newStyle: DaySelectorStyle) { style = newStyle updateState() } @@ -79,7 +79,7 @@ class DateLabel: UILabel, DaySelectorItemProtocol { return false } - func animate(){ + private func animate(){ UIView.transition(with: self, duration: 0.4, options: .transitionCrossDissolve, @@ -88,10 +88,10 @@ class DateLabel: UILabel, DaySelectorItemProtocol { }, completion: nil) } - override func layoutSubviews() { + override public func layoutSubviews() { layer.cornerRadius = bounds.height / 2 } - override func tintColorDidChange() { + override public func tintColorDidChange() { updateState() } } diff --git a/Source/Header/DaySelector/DayDateCell.swift b/Source/Header/DaySelector/DayDateCell.swift index 2be34928..aebbeb2b 100644 --- a/Source/Header/DaySelector/DayDateCell.swift +++ b/Source/Header/DaySelector/DayDateCell.swift @@ -2,21 +2,21 @@ import UIKit import DateToolsSwift import Neon -class DayDateCell: UIView, DaySelectorItemProtocol { +public final class DayDateCell: UIView, DaySelectorItemProtocol { - let dateLabel = DateLabel() - let dayLabel = UILabel() + private let dateLabel = DateLabel() + private let dayLabel = UILabel() - var regularSizeClassFontSize: CGFloat = 16 + private var regularSizeClassFontSize: CGFloat = 16 - var date = Date() { + public var date = Date() { didSet { dateLabel.date = date updateState() } } - var calendar = Calendar.autoupdatingCurrent { + public var calendar = Calendar.autoupdatingCurrent { didSet { dateLabel.calendar = calendar updateState() @@ -24,7 +24,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol { } - var selected: Bool { + public var selected: Bool { get { return dateLabel.selected } @@ -35,7 +35,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol { var style = DaySelectorStyle() - override var intrinsicContentSize: CGSize { + override public var intrinsicContentSize: CGSize { return CGSize(width: 75, height: 35) } @@ -49,18 +49,18 @@ class DayDateCell: UIView, DaySelectorItemProtocol { configure() } - func configure() { + private func configure() { clipsToBounds = true [dayLabel, dateLabel].forEach(addSubview(_:)) } - func updateStyle(_ newStyle: DaySelectorStyle) { + public func updateStyle(_ newStyle: DaySelectorStyle) { style = newStyle dateLabel.updateStyle(newStyle) updateState() } - func updateState() { + private func updateState() { let isWeekend = isAWeekend(date: date) dayLabel.font = UIFont.systemFont(ofSize: regularSizeClassFontSize) dayLabel.textColor = isWeekend ? style.weekendTextColor : style.inactiveTextColor @@ -69,7 +69,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol { setNeedsLayout() } - func updateDayLabel() { + private func updateDayLabel() { let daySymbols = calendar.shortWeekdaySymbols let weekendMask = [true] + [Bool](repeating: false, count: 5) + [true] var weekDays = Array(zip(daySymbols, weekendMask)) @@ -90,7 +90,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol { return false } - override func layoutSubviews() { + override public func layoutSubviews() { super.layoutSubviews() dayLabel.sizeToFit() dayLabel.center.y = center.y @@ -106,7 +106,7 @@ class DayDateCell: UIView, DaySelectorItemProtocol { label.frame.origin.x += padding } } - override func tintColorDidChange() { + override public func tintColorDidChange() { updateState() } } diff --git a/Source/Header/DaySelector/DaySelector.swift b/Source/Header/DaySelector/DaySelector.swift index a3c787db..80bceec5 100644 --- a/Source/Header/DaySelector/DaySelector.swift +++ b/Source/Header/DaySelector/DaySelector.swift @@ -9,13 +9,12 @@ public protocol DaySelectorItemProtocol: AnyObject { func updateStyle(_ newStyle: DaySelectorStyle) } -protocol DaySelectorDelegate: AnyObject { +public protocol DaySelectorDelegate: AnyObject { func dateSelectorDidSelectDate(_ date: Date) } -class DaySelector: UIView { - - weak var delegate: DaySelectorDelegate? +public final class DaySelector: UIView { + public weak var delegate: DaySelectorDelegate? public var calendar = Calendar.autoupdatingCurrent { didSet { @@ -29,16 +28,16 @@ class DaySelector: UIView { } } - var style = DaySelectorStyle() + private var style = DaySelectorStyle() - var daysInWeek = 7 - var startDate: Date! { + private var daysInWeek = 7 + public var startDate: Date! { didSet { configure() } } - var selectedIndex = -1 { + public var selectedIndex = -1 { didSet { items.filter {$0.selected == true} .first?.selected = false @@ -49,7 +48,7 @@ class DaySelector: UIView { } } - var selectedDate: Date? { + public var selectedDate: Date? { get { return items.filter{$0.selected == true}.first?.date as Date? } @@ -60,9 +59,9 @@ class DaySelector: UIView { } } - var items = [UIView & DaySelectorItemProtocol]() + private var items = [UIView & DaySelectorItemProtocol]() - init(startDate: Date = Date(), daysInWeek: Int = 7) { + public init(startDate: Date = Date(), daysInWeek: Int = 7) { self.startDate = startDate.dateOnly(calendar: calendar) self.daysInWeek = daysInWeek super.init(frame: CGRect.zero) @@ -70,7 +69,7 @@ class DaySelector: UIView { configure() } - override init(frame: CGRect) { + override public init(frame: CGRect) { startDate = Date().dateOnly(calendar: calendar) super.init(frame: frame) initializeViews(viewType: DateLabel.self) @@ -82,7 +81,7 @@ class DaySelector: UIView { initializeViews(viewType: DateLabel.self) } - func initializeViews(viewType: T.Type) where T: DaySelectorItemProtocol { + private func initializeViews(viewType: T.Type) where T: DaySelectorItemProtocol { // Store last selected date let lastSelectedDate = selectedDate @@ -106,22 +105,22 @@ class DaySelector: UIView { selectedDate = lastSelectedDate } - func configure() { + private func configure() { for (increment, label) in items.enumerated() { label.date = startDate.add(TimeChunk.dateComponents(days: increment), calendar: calendar) } } - func updateStyle(_ newStyle: DaySelectorStyle) { + public func updateStyle(_ newStyle: DaySelectorStyle) { style = newStyle items.forEach{$0.updateStyle(style)} } - func prepareForReuse() { + public func prepareForReuse() { items.forEach {$0.selected = false} } - override func layoutSubviews() { + override public func layoutSubviews() { super.layoutSubviews() let itemCount = CGFloat(items.count) @@ -142,7 +141,7 @@ class DaySelector: UIView { } } - func transitionToHorizontalSizeClass(_ sizeClass: UIUserInterfaceSizeClass) { + public func transitionToHorizontalSizeClass(_ sizeClass: UIUserInterfaceSizeClass) { switch sizeClass { case .regular: initializeViews(viewType: DayDateCell.self) @@ -151,7 +150,7 @@ class DaySelector: UIView { } } - @objc func dateLabelDidTap(_ sender: UITapGestureRecognizer) { + @objc private func dateLabelDidTap(_ sender: UITapGestureRecognizer) { if let item = sender.view as? DaySelectorItemProtocol { delegate?.dateSelectorDidSelectDate(item.date) } diff --git a/Source/Header/DaySelector/DaySelectorController.swift b/Source/Header/DaySelector/DaySelectorController.swift index 74f579b6..ad1093b0 100644 --- a/Source/Header/DaySelector/DaySelectorController.swift +++ b/Source/Header/DaySelector/DaySelectorController.swift @@ -1,9 +1,9 @@ import UIKit -class DaySelectorController: UIViewController { - lazy var daySelector = DaySelector() +public final class DaySelectorController: UIViewController { + public private(set) lazy var daySelector = DaySelector() - var delegate: DaySelectorDelegate? { + public var delegate: DaySelectorDelegate? { get { return daySelector.delegate } @@ -21,7 +21,7 @@ class DaySelectorController: UIViewController { } } - var startDate: Date { + public var startDate: Date { get { return daySelector.startDate! } @@ -30,7 +30,7 @@ class DaySelectorController: UIViewController { } } - var selectedIndex: Int { + public var selectedIndex: Int { get { return daySelector.selectedIndex } @@ -39,7 +39,7 @@ class DaySelectorController: UIViewController { } } - var selectedDate: Date? { + public var selectedDate: Date? { get { return daySelector.selectedDate } @@ -48,7 +48,7 @@ class DaySelectorController: UIViewController { } } - override func loadView() { + override public func loadView() { view = daySelector } @@ -56,7 +56,7 @@ class DaySelectorController: UIViewController { daySelector.transitionToHorizontalSizeClass(sizeClass) } - func updateStyle(_ newStyle: DaySelectorStyle) { + public func updateStyle(_ newStyle: DaySelectorStyle) { daySelector.updateStyle(newStyle) } } diff --git a/Source/Header/DaySymbolsView.swift b/Source/Header/DaySymbolsView.swift index cbb7b045..3fdafbe3 100644 --- a/Source/Header/DaySymbolsView.swift +++ b/Source/Header/DaySymbolsView.swift @@ -1,13 +1,12 @@ import UIKit -class DaySymbolsView: UIView { +public final class DaySymbolsView: UIView { + public private(set) var daysInWeek = 7 + private var calendar = Calendar.autoupdatingCurrent + private var labels = [UILabel]() + private var style: DaySymbolsStyle = DaySymbolsStyle() - var daysInWeek = 7 - var calendar = Calendar.autoupdatingCurrent - var labels = [UILabel]() - var style: DaySymbolsStyle = DaySymbolsStyle() - - override init(frame: CGRect) { + override public init(frame: CGRect) { super.init(frame: frame) initializeViews() } @@ -17,14 +16,14 @@ class DaySymbolsView: UIView { initializeViews() } - init(daysInWeek: Int = 7, calendar: Calendar = Calendar.autoupdatingCurrent) { + public init(daysInWeek: Int = 7, calendar: Calendar = Calendar.autoupdatingCurrent) { self.calendar = calendar self.daysInWeek = daysInWeek super.init(frame: CGRect.zero) initializeViews() } - func initializeViews() { + private func initializeViews() { for _ in 1...daysInWeek { let label = UILabel() label.textAlignment = .center @@ -34,12 +33,12 @@ class DaySymbolsView: UIView { configure() } - func updateStyle(_ newStyle: DaySymbolsStyle) { + public func updateStyle(_ newStyle: DaySymbolsStyle) { style = newStyle configure() } - func configure() { + private func configure() { let daySymbols = calendar.veryShortWeekdaySymbols let weekendMask = [true] + [Bool](repeating: false, count: 5) + [true] var weekDays = Array(zip(daySymbols, weekendMask)) @@ -54,7 +53,7 @@ class DaySymbolsView: UIView { } - override func layoutSubviews() { + override public func layoutSubviews() { let labelsCount = CGFloat(labels.count) var per = bounds.width - bounds.height * labelsCount diff --git a/Source/Header/SwipeLabelView.swift b/Source/Header/SwipeLabelView.swift index 97337480..9b5b2956 100644 --- a/Source/Header/SwipeLabelView.swift +++ b/Source/Header/SwipeLabelView.swift @@ -1,14 +1,13 @@ import UIKit -class SwipeLabelView: UIView, DayViewStateUpdating { - - enum AnimationDirection { +public final class SwipeLabelView: UIView, DayViewStateUpdating { + public enum AnimationDirection { case Forward case Backward } - var calendar = Calendar.autoupdatingCurrent - weak var state: DayViewState? { + public private(set) var calendar = Calendar.autoupdatingCurrent + public weak var state: DayViewState? { willSet(newValue) { state?.unsubscribe(client: self) } @@ -22,25 +21,25 @@ class SwipeLabelView: UIView, DayViewStateUpdating { labels.first!.text = formattedDate(date: state!.selectedDate) } - var firstLabel: UILabel { + private var firstLabel: UILabel { return labels.first! } - var secondLabel: UILabel { + private var secondLabel: UILabel { return labels.last! } - var labels = [UILabel]() + private var labels = [UILabel]() - var style = SwipeLabelStyle() + private var style = SwipeLabelStyle() - init(calendar: Calendar = Calendar.autoupdatingCurrent) { + public init(calendar: Calendar = Calendar.autoupdatingCurrent) { self.calendar = calendar super.init(frame: .zero) configure() } - override init(frame: CGRect) { + override public init(frame: CGRect) { super.init(frame: frame) configure() } @@ -50,7 +49,7 @@ class SwipeLabelView: UIView, DayViewStateUpdating { configure() } - func configure() { + private func configure() { for _ in 0...1 { let label = UILabel() label.textAlignment = .center @@ -60,7 +59,7 @@ class SwipeLabelView: UIView, DayViewStateUpdating { updateStyle(style) } - func updateStyle(_ newStyle: SwipeLabelStyle) { + public func updateStyle(_ newStyle: SwipeLabelStyle) { style = newStyle labels.forEach { label in label.textColor = style.textColor @@ -68,7 +67,7 @@ class SwipeLabelView: UIView, DayViewStateUpdating { } } - func animate(_ direction: AnimationDirection) { + private func animate(_ direction: AnimationDirection) { let multiplier: CGFloat = direction == .Forward ? -1 : 1 let shiftRatio: CGFloat = 30/375 let screenWidth = bounds.width @@ -87,7 +86,7 @@ class SwipeLabelView: UIView, DayViewStateUpdating { }) } - override func layoutSubviews() { + override public func layoutSubviews() { for subview in subviews { subview.frame = bounds } @@ -95,7 +94,7 @@ class SwipeLabelView: UIView, DayViewStateUpdating { // MARK: DayViewStateUpdating - func move(from oldDate: Date, to newDate: Date) { + public func move(from oldDate: Date, to newDate: Date) { guard newDate != oldDate else { return } labels.last!.text = formattedDate(date: newDate)